CommunityController.class.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class CommunityController extends CommonController {
  16. public function get_member_ziti_order()
  17. {
  18. $gpc = I('request.');
  19. $xq_member_id = $gpc['memberId'];
  20. $token = $gpc['token'];
  21. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  22. $member_id = $weprogram_token['member_id'];
  23. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  24. if( empty($member_info) )
  25. {
  26. echo json_encode( array('code' => 2) );
  27. die();
  28. }
  29. $community_info = D('Home/Front')->get_member_community_info($member_id);
  30. if( empty($community_info) && $member_info['pickup_id'] > 0 )
  31. {
  32. $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' =>$member_id ) )->find();
  33. if(!empty($parent_community_info))
  34. {
  35. $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
  36. }
  37. }
  38. if( empty($community_info) || $community_info['state'] != 1 )
  39. {
  40. echo json_encode( array('code' => 2) );
  41. die();
  42. }
  43. $where = ' and o.head_id = '.$community_info['id']." and o.member_id = ".$xq_member_id;
  44. $where .= ' and o.order_status_id = 4 ';
  45. $sql = "select o.order_id,o.order_num_alias,o.date_added,o.delivery,o.is_pin,o.is_zhuli,o.shipping_fare,o.voucher_credit,o.store_id,o.total,o.order_status_id,o.lottery_win,o.type,os.name as status_name,o.shipping_name,o.shipping_tel,o.payment_code "
  46. . " from ".C('DB_PREFIX')."lionfish_comshop_order as o ,
  47. ".C('DB_PREFIX')."lionfish_comshop_order_status as os
  48. where o.delivery != 'express' and o.delivery != 'hexiao' and o.order_status_id = os.order_status_id {$where}
  49. order by o.date_added desc ";
  50. $list = M()->query($sql);
  51. //createTime
  52. foreach($list as $key => $val)
  53. {
  54. $val['checked'] = 1;
  55. if($val['delivery'] == 'pickup')
  56. {
  57. //$val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
  58. }else{
  59. //$val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
  60. }
  61. $val['createTime'] = date('Y-m-d H:i:s', $val['date_added']);
  62. // $val['delivery'] =='pickup'
  63. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  64. {
  65. $val['shipping_fare'] = '免运费';
  66. }else{
  67. $val['shipping_fare'] = '运费:'.$val['shipping_fare'];
  68. }
  69. if($val['order_status_id'] == 10)
  70. {
  71. $val['status_name'] = '等待退款';
  72. }
  73. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  74. {
  75. //delivery 6
  76. $val['status_name'] = '待自提';
  77. //已自提
  78. }
  79. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  80. {
  81. //delivery 6
  82. $val['status_name'] = '已自提';
  83. //已自提
  84. }
  85. else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  86. {
  87. //等待开奖
  88. //一等奖
  89. if($val['lottery_win'] == 1)
  90. {
  91. $val['status_name'] = '一等奖';
  92. }else {
  93. $val['status_name'] = '等待开奖';
  94. }
  95. }
  96. else if($val['order_status_id'] == 2 && $val['type'] == 'lottery')
  97. {
  98. //等待开奖
  99. $val['status_name'] = '等待开奖';
  100. }
  101. $quantity = 0;
  102. $url = D('Home/Front')->get_config_by_name('shop_domain').'/';
  103. $goods_sql = "select order_id,order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,rela_goodsoption_valueid,is_refund_state,has_refund_money,has_refund_quantity"
  104. . " from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id= ".$val['order_id']."";
  105. $goods_list = M()->query($goods_sql); //M()->query($goods_sql);
  106. foreach($goods_list as $kk => $vv)
  107. {
  108. //commision
  109. if($is_tuanz == 1){
  110. $community_order_info = M('lionfish_community_head_commiss_order')->where( array('head_id' => $community_info['id'],'order_goods_id' => $vv['order_goods_id']) )->find();
  111. if(!empty($community_order_info))
  112. {
  113. $vv['commision'] = $community_order_info['money'];
  114. }else{
  115. $vv['commision'] = 0;
  116. }
  117. }
  118. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $vv['order_goods_id']) )->select();
  119. if( !empty($vv['goods_images']))
  120. {
  121. $goods_images = $url.resize($vv['goods_images'],400,400);
  122. if(is_array($goods_images))
  123. {
  124. $vv['goods_images'] = $vv['goods_images'];
  125. }else{
  126. $vv['goods_images']= $url.resize($vv['goods_images'],400,400) ;
  127. }
  128. }else{
  129. $vv['goods_images']= '';
  130. }
  131. $goods_filed = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $vv['goods_id']) )->find();
  132. $vv['orign_price'] = $goods_filed['price'];
  133. $quantity += $vv['quantity'];
  134. foreach($order_option_list as $option)
  135. {
  136. $vv['option_str'][] = $option['value'];
  137. }
  138. if( !isset($vv['option_str']) )
  139. {
  140. $vv['option_str'] = '';
  141. }else{
  142. $vv['option_str'] = implode(',', $vv['option_str']);
  143. }
  144. $vv['price'] = round($vv['price'],2);
  145. $vv['orign_price'] = round($vv['orign_price'],2);
  146. $vv['checked'] = 1;
  147. if( $vv['is_refund_state'] == 1 || ($vv['has_refund_money'] > 0 && $vv['has_refund_quantity'] > 0) )
  148. {
  149. $vv['is_refund_state'] = 1;
  150. $where = " order_id = '".$vv['order_id']."' and order_goods_id = '".$vv['order_goods_id']."' and state in (0,2,3) ";
  151. $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
  152. if(!empty($refund_info)){
  153. $vv['refund_info'] = $refund_info;
  154. }else{
  155. $refund_info = array();
  156. $refund_info['order_id'] = $val['order_id'];
  157. $refund_info['ref_money'] = $vv['has_refund_money'];
  158. $refund_info['real_refund_quantity'] = $vv['has_refund_quantity'];
  159. $refund_info['state'] = 3;
  160. $vv['refund_info'] = $refund_info;
  161. }
  162. }
  163. $goods_list[$kk] = $vv;
  164. }
  165. $val['quantity'] = $quantity;
  166. if( empty($val['store_id']) )
  167. {
  168. $val['store_id'] = 1;
  169. }
  170. $store_info = array('s_true_name' =>'','s_logo' => '');
  171. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  172. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  173. if( !empty($store_info['s_logo']))
  174. {
  175. $store_info['s_logo'] = $url .tomedia($store_info['s_logo']);
  176. }else{
  177. $store_info['s_logo'] = '';
  178. }
  179. $order_goods['store_info'] = $store_info;
  180. $val['store_info'] = $store_info;
  181. $val['goods_list'] = $goods_list;
  182. if($val['type'] == 'integral')
  183. {
  184. //暂时屏蔽积分
  185. //$integral_order = M('integral_order')->field('score')->where( array('order_id' => $val['order_id']) )->find();
  186. //$val['score'] = intval($integral_order['score']);
  187. }
  188. $val['total'] = round($val['total'],2);
  189. //货到付款订单
  190. if($val['payment_code'] == 'cashon_delivery'){
  191. $val['cashondelivery_code_img'] = D('Home/Front')->getCashonDeliveryCode();
  192. }
  193. $list[$key] = $val;
  194. }
  195. $need_data = array('code' => 0);
  196. if( !empty($list) )
  197. {
  198. $need_data['data'] = $list;
  199. }else {
  200. $need_data = array('code' => 1);
  201. }
  202. echo json_encode( $need_data );
  203. die();
  204. }
  205. public function get_community_zhitui_qrcode()
  206. {
  207. $_GPC = I('request.');
  208. $token = $_GPC['token'];
  209. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  210. $member_id = $weprogram_token['member_id'];
  211. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  212. if( empty($member_info) )
  213. {
  214. echo json_encode( array('code' => 1) );
  215. die();
  216. }
  217. $community_info = D('Home/Front')->get_member_community_info($member_id);
  218. if( empty($community_info) || $community_info['state'] != 1 )
  219. {
  220. echo json_encode( array('code' => 1) );
  221. die();
  222. }
  223. $head_id = $community_info['id'];
  224. $community_zhitui_qrcode_json = D('Home/Front')->get_config_by_name("community_zhitui_qrcode".$head_id);
  225. if( empty($community_zhitui_qrcode_json) )
  226. {
  227. $path = "lionfish_comshop/moduleA/groupCenter/apply";
  228. $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  229. if( empty($zhitui_qrcod) )
  230. {
  231. $zhitui_qrcod = '';
  232. }else{
  233. $zhitui_qrcod = tomedia($zhitui_qrcod);
  234. $arr = array();
  235. $arr['qrcode'] = $zhitui_qrcod;
  236. $arr['express_time'] = time() + 600;
  237. $hd_key = "community_zhitui_qrcode".$head_id;
  238. D('Seller/Config')->update( array( $hd_key => serialize($arr)) );
  239. }
  240. echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
  241. die();
  242. }else{
  243. $community_zhitui_qrcode_arr = unserialize($community_zhitui_qrcode_json);
  244. if( $community_zhitui_qrcode_arr['express_time'] < time() )
  245. {
  246. $path = "lionfish_comshop/moduleA/groupCenter/apply";
  247. $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  248. if( empty($zhitui_qrcod) )
  249. {
  250. $zhitui_qrcod = '';
  251. }else{
  252. $zhitui_qrcod = tomedia($zhitui_qrcod);
  253. $arr = array();
  254. $arr['qrcode'] = $zhitui_qrcod;
  255. $arr['express_time'] = time() + 600;
  256. $ky = "community_zhitui_qrcode".$head_id;
  257. D('Seller/Config')->update( array( $ky => serialize($arr) ) );
  258. }
  259. echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
  260. die();
  261. }else{
  262. echo json_encode( array('code' => 0, 'qrcode' => $community_zhitui_qrcode_arr['qrcode'] ) );
  263. die();
  264. }
  265. }
  266. }
  267. //------begin---
  268. /**
  269. 获取团长绑定核销人员二维码接口
  270. **/
  271. public function get_community_bind_member_qrcode()
  272. {
  273. $_GPC = I('request.');
  274. $token = $_GPC['token'];
  275. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  276. $member_id = $weprogram_token['member_id'];
  277. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  278. if( empty($member_info) )
  279. {
  280. echo json_encode( array('code' => 1) );
  281. die();
  282. }
  283. $community_info = D('Home/Front')->get_member_community_info($member_id);
  284. if( empty($community_info) || $community_info['state'] != 1 )
  285. {
  286. echo json_encode( array('code' => 1) );
  287. die();
  288. }
  289. $head_id = $community_info['id'];
  290. $community_memberbind_qrcode = D('Home/Front')->get_config_by_name('community_memberbind_qrcode'.$head_id);
  291. if( empty($community_memberbind_qrcode) )
  292. {
  293. $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
  294. $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  295. $data = array();
  296. $data['time'] = time();
  297. $data['hexiao_qrcod'] = $hexiao_qrcod;
  298. $kd_lcc = 'community_memberbind_qrcode'.$head_id;
  299. D('Seller/Config')->update( array( $kd_lcc => serialize($data) ) );
  300. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
  301. die();
  302. }else{
  303. $hexiao_data = unserialize($community_memberbind_qrcode);
  304. if($hexiao_data['time'] + 600 < time() )
  305. {
  306. $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
  307. $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
  308. $data = array();
  309. $data['time'] = time();
  310. $data['hexiao_qrcod'] = $hexiao_qrcod;
  311. $ky = 'community_memberbind_qrcode'.$head_id;
  312. D('Seller/Config')->update( array( $ky => serialize($data) ) );
  313. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
  314. die();
  315. }else{
  316. echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_data['hexiao_qrcod']) ) );
  317. die();
  318. }
  319. }
  320. }
  321. /**
  322. 团长的核销人员列表
  323. **/
  324. public function get_community_hexiao_memberlist()
  325. {
  326. $_GPC = I('request.');
  327. $token = $_GPC['token'];
  328. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  329. $member_id = $weprogram_token['member_id'];
  330. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  331. if( empty($member_info) )
  332. {
  333. echo json_encode( array('code' => 1) );
  334. die();
  335. }
  336. $community_info = D('Home/Front')->get_member_community_info($member_id);
  337. if( empty($community_info) || $community_info['state'] != 1 )
  338. {
  339. echo json_encode( array('code' => 1) );
  340. die();
  341. }
  342. $head_id = $community_info['id'];
  343. $member_list = M()->query("select * from ".C('DB_PREFIX').
  344. "lionfish_comshop_community_pickup_member where community_id={$head_id} and state = 1 order by id desc ");
  345. if( empty($member_list) )
  346. {
  347. echo json_encode( array('code' => 1, 'log' => '暂时没有核销人员') );
  348. die();
  349. }else{
  350. foreach( $member_list as $key => $val )
  351. {
  352. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' =>$val['member_id'] ) )->find();
  353. $member_record_count_arr = M()->query(" select count(order_id) as count from ".C('DB_PREFIX')
  354. ."lionfish_comshop_community_pickup_member_record where member_id=".$val['member_id'] );
  355. $member_record_count = $member_record_count_arr[0]['count'];
  356. $val['avatar'] = $mb_info['avatar'];
  357. $val['username'] = $mb_info['username'];
  358. $val['member_record_count'] = $member_record_count;
  359. $member_list[$key] = $val;
  360. //ims_lionfish_comshop_community_pickup_member_record
  361. }
  362. echo json_encode( array('code' => 0, 'member_list' => $member_list) );
  363. die();
  364. }
  365. //ims_lionfish_comshop_community_pickup_member
  366. }
  367. /**
  368. 绑定
  369. **/
  370. public function bind_community_member_do()
  371. {
  372. $_GPC = I('request.');
  373. $token = $_GPC['token'];
  374. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  375. $member_id = $weprogram_token['member_id'];
  376. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  377. if( empty($member_info) )
  378. {
  379. echo json_encode( array('code' => 1) );
  380. die();
  381. }
  382. $name = $_GPC['name'];
  383. $mobile = $_GPC['mobile'];
  384. $community_id = $_GPC['community_id'];
  385. $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id) )->find();
  386. if( !empty($is_in_info) )
  387. {
  388. echo json_encode( array('code' => 0) );
  389. die();
  390. }
  391. //pickup_id
  392. //lionfish_comshop_community_pickup_member
  393. $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
  394. if( !empty($is_in_info) )
  395. {
  396. echo json_encode( array('code' => 0) );
  397. die();
  398. }
  399. $ins_data = array();
  400. $ins_data['community_id'] = $community_id;
  401. $ins_data['member_id'] = $member_id;
  402. $ins_data['state'] = 1;
  403. $ins_data['remark'] = '前台扫码添加,姓名:'.$name.',手机号:'.$mobile;
  404. $ins_data['addtime'] = time();
  405. $pickup_id = M('lionfish_comshop_community_pickup_member')->add($ins_data);
  406. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('pickup_id' => $pickup_id ));
  407. echo json_encode( array('code' => 0) );
  408. die();
  409. }
  410. //2、查看会员核销记录的
  411. public function get_member_hexiao_orderlist()
  412. {
  413. $_GPC = I('request.');
  414. $token = $_GPC['token'];
  415. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  416. $member_id = $weprogram_token['member_id'];
  417. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  418. if( empty($member_info) )
  419. {
  420. echo json_encode( array('code' => 1) );
  421. die();
  422. }
  423. //lionfish_comshop_community_pickup_member_record
  424. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  425. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  426. $offset = ($page - 1)* $size;
  427. $where = " and member_id = {$member_id} ";
  428. $sql = "select *
  429. from ".C('DB_PREFIX')."lionfish_comshop_community_pickup_member_record
  430. where 1 {$where}
  431. order by id desc limit {$offset},{$size}";
  432. $list = M()->query($sql);
  433. if( !empty($list) )
  434. {
  435. foreach($list as $key => $val)
  436. {
  437. $mb_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' =>$val['member_id'] ) )->find();
  438. $val['username'] = $mb_info['username'];
  439. $val['avatar'] = $mb_info['avatar'];
  440. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  441. $list[$key] = $val;
  442. }
  443. }
  444. if( empty($list) )
  445. {
  446. echo json_encode(array('code' => 1));
  447. die();
  448. }else{
  449. echo json_encode( array('code' =>0, 'data' => $list) );
  450. die();
  451. }
  452. }
  453. //------end----
  454. /***
  455. 团长对清单进行收货
  456. **/
  457. public function sub_head_delivery()
  458. {
  459. $gpc = I('request.');
  460. $token = $gpc['token'];
  461. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  462. $member_id = $weprogram_token['member_id'];
  463. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  464. if( empty($member_info) )
  465. {
  466. echo json_encode( array('code' => 1) );
  467. die();
  468. }
  469. $community_info = D('Home/Front')->get_member_community_info($member_id);
  470. if( empty($community_info) || $community_info['state'] != 1 )
  471. {
  472. echo json_encode( array('code' => 1) );
  473. die();
  474. }
  475. $head_id = $community_info['id'];
  476. $list_id = $gpc['list_id'];
  477. $list_info = M('lionfish_comshop_deliverylist')->where( array('id' => $list_id, 'head_id' => $head_id) )->find();
  478. if( !empty($list_info) )
  479. {
  480. M('lionfish_comshop_deliverylist')->where( array('id' => $list_id ) )->save( array('state' => 2,'head_get_time' => time() ) );
  481. //对订单操作,可以去提货了 load_model_class('frontorder')->send_order_operate($order_id);
  482. $order_ids_all = M('lionfish_comshop_deliverylist_order')->where( array('list_id' => $list_id ) )->select();
  483. if( !empty($order_ids_all) )
  484. {
  485. foreach($order_ids_all as $order_val)
  486. {
  487. $order_status_id_info = M('lionfish_comshop_order')->field('order_status_id')->where( array('order_id' => $order_val['order_id'] ) )->find();
  488. $order_status_id = $order_status_id_info['order_status_id'];
  489. //配送中才能
  490. if($order_status_id == 14)
  491. {
  492. $history_data = array();
  493. $history_data['order_id'] = $order_val['order_id'];
  494. $history_data['order_status_id'] = 4;
  495. $history_data['notify'] = 0;
  496. $history_data['comment'] = '前台团长签收配送清单';
  497. $history_data['date_added'] = time();
  498. M('lionfish_comshop_order_history')->add( $history_data );
  499. //send_order_operate
  500. D('Home/Frontorder')->send_order_operate($order_val['order_id']);
  501. }
  502. }
  503. }
  504. echo json_encode( array('code' => 0) );
  505. die();
  506. }else{
  507. echo json_encode( array('code' => 1) );
  508. die();
  509. }
  510. }
  511. /**
  512. 获取团长清单的商品列表
  513. **/
  514. public function get_head_deliverygoods()
  515. {
  516. $gpc = I('request.');
  517. $token = $gpc['token'];
  518. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  519. $member_id = $weprogram_token['member_id'];
  520. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  521. if( empty($member_info) )
  522. {
  523. echo json_encode( array('code' => 1) );
  524. die();
  525. }
  526. $community_info = D('Home/Front')->get_member_community_info($member_id);
  527. if( empty($community_info) || $community_info['state'] != 1 )
  528. {
  529. echo json_encode( array('code' => 1) );
  530. die();
  531. }
  532. $head_id = $community_info['id'];
  533. //lionfish_comshop_deliverylist_goods
  534. $list_id = $gpc['list_id'];
  535. $page = isset($gpc['page']) ? $gpc['page']:'1';
  536. $size = isset($gpc['size']) ? $gpc['size']:'20';
  537. $offset = ($page - 1)* $size;
  538. $where = " and list_id = {$list_id} ";
  539. $sql = "select *
  540. from ".C('DB_PREFIX')."lionfish_comshop_deliverylist_goods
  541. where 1 {$where}
  542. order by id desc limit {$offset},{$size}";
  543. $list = M()->query($sql);
  544. if( !empty($list) )
  545. {
  546. foreach($list as $key => $val)
  547. {
  548. $val['goods_image'] = tomedia($val['goods_image']);
  549. $list[$key] = $val;
  550. }
  551. }
  552. if( empty($list) )
  553. {
  554. echo json_encode(array('code' => 1));
  555. die();
  556. }else{
  557. echo json_encode( array('code' =>0, 'data' => $list) );
  558. die();
  559. }
  560. }
  561. /**
  562. 获取团长的清单
  563. **/
  564. public function get_head_deliverylist()
  565. {
  566. $gpc = I('request.');
  567. $token = $gpc['token'];
  568. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  569. $member_id = $weprogram_token['member_id'];
  570. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  571. if( empty($member_info) )
  572. {
  573. echo json_encode( array('code' => 1) );
  574. die();
  575. }
  576. $community_info = D('Home/Front')->get_member_community_info($member_id);
  577. if( empty($community_info) || $community_info['state'] != 1 )
  578. {
  579. echo json_encode( array('code' => 1) );
  580. die();
  581. }
  582. $head_id = $community_info['id'];
  583. $page = isset($gpc['page']) ? $gpc['page']:'1';
  584. $size = isset($gpc['size']) ? $gpc['size']:'6';
  585. $offset = ($page - 1)* $size;
  586. $where = " and head_id = {$head_id} ";
  587. $status = isset( $gpc['status'] ) ? $gpc['status']: -1;
  588. $kyw = isset( $gpc['keywords'] ) ? $gpc['keywords']: '';
  589. if($status >= 0)
  590. {
  591. $where .= " and state = {$status} ";
  592. } else {
  593. }
  594. if(!empty($kyw))
  595. {
  596. $where .= ' and (head_name like "%'.$kyw.'%" or head_mobile like "%'.$kyw.'%" or line_name like "%'.$kyw.'%" or clerk_name like "%'.$kyw.'%" or clerk_mobile like "%'.$kyw.'%" )';
  597. }
  598. $sql = "select *
  599. from ".C('DB_PREFIX')."lionfish_comshop_deliverylist
  600. where 1 {$where}
  601. order by id desc limit {$offset},{$size}";
  602. $list = M()->query($sql);
  603. if( !empty($list) )
  604. {
  605. foreach ($list as $key => &$val) {
  606. $val['express_time'] = $val['express_time'] ? date('Y-m-d H:i', $val['express_time']) : '';
  607. $val['head_get_time'] = $val['head_get_time'] ? date('Y-m-d H:i', $val['head_get_time']) : '';
  608. $val['create_time'] = $val['create_time'] ? date('Y-m-d H:i',$val['create_time']) : '';
  609. }
  610. }
  611. if( empty($list) )
  612. {
  613. echo json_encode(array('code' => 1));
  614. die();
  615. }else{
  616. echo json_encode( array('code' =>0, 'data' => $list) );
  617. die();
  618. }
  619. }
  620. //--
  621. public function headorderlist()
  622. {
  623. $gpc = I('request.');
  624. $token = $gpc['token'];
  625. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  626. $member_id = $weprogram_token['member_id'];
  627. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  628. if( empty($member_info) )
  629. {
  630. echo json_encode( array('code' => 1) );
  631. die();
  632. }
  633. $community_info = D('Home/Front')->get_member_community_info($member_id);
  634. if( empty($community_info) || $community_info['state'] != 1 )
  635. {
  636. echo json_encode( array('code' => 1) );
  637. die();
  638. }
  639. $head_id = $community_info['id'];
  640. $page = isset($gpc['page']) ? $gpc['page']:'1';
  641. $size = isset($gpc['size']) ? $gpc['size']:'6';
  642. $offset = ($page - 1)* $size;
  643. $where = " and co.head_id = {$head_id} ";
  644. $order_status = $gpc['order_status'];
  645. if($order_status == 1)
  646. {
  647. $where .= " and co.state = 0 ";
  648. } else if($order_status == 2){
  649. $where .= " and co.state = 1 ";
  650. }
  651. /*$sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name
  652. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  653. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  654. where co.order_goods_id = og.order_goods_id {$where}
  655. order by co.id desc limit {$offset},{$size}";*/
  656. $sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name,co.type
  657. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co left join
  658. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og on co.order_goods_id = og.order_goods_id
  659. where 1=1 {$where}
  660. order by co.id desc limit {$offset},{$size}";
  661. $list = M()->query($sql);
  662. if( !empty($list) )
  663. {
  664. foreach($list as $key => $val)
  665. {
  666. $val['total'] = sprintf("%.2f",$val['total']);
  667. $val['money'] = sprintf("%.2f",$val['money']);
  668. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  669. $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id']) )->find();
  670. $val['order_num_alias'] = $order_info['order_num_alias'];
  671. if($val['type'] == 'tuijian'){
  672. $val['name'] = "推荐团长现金奖励";
  673. }
  674. $list[$key] = $val;
  675. }
  676. }
  677. if( empty($list) )
  678. {
  679. echo json_encode(array('code' => 1));
  680. die();
  681. }else{
  682. echo json_encode( array('code' =>0, 'data' => $list) );
  683. die();
  684. }
  685. }
  686. public function cashlist()
  687. {
  688. $gpc = I('request.');
  689. $token = $gpc['token'];
  690. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  691. $member_id = $weprogram_token['member_id'];
  692. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  693. if( empty($member_info) )
  694. {
  695. echo json_encode( array('code' => 1) );
  696. die();
  697. }
  698. $community_info = D('Home/Front')->get_member_community_info($member_id);
  699. if( empty($community_info) || $community_info['state'] != 1 )
  700. {
  701. echo json_encode( array('code' => 1) );
  702. die();
  703. }
  704. $page = isset($gpc['page']) ? $gpc['page']:'1';
  705. $size = isset($gpc['size']) ? $gpc['size']:'6';
  706. $offset = ($page - 1)* $size;
  707. //begin select
  708. $sql = "select *
  709. from ".C('DB_PREFIX')."lionfish_community_head_tixian_order
  710. where head_id =".$community_info['id']." and member_id={$member_id} order by id desc limit {$offset},{$size}";
  711. $list = M()->query($sql);
  712. foreach($list as $key => $val)
  713. {
  714. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  715. $val['id'] = sprintf("%04d", $val['id']);
  716. $list[$key] = $val;
  717. }
  718. if( empty($list) )
  719. {
  720. echo json_encode( array('code' => 1) );
  721. die();
  722. } else{
  723. echo json_encode( array('code' => 0, 'data' => $list) );
  724. die();
  725. }
  726. //ims_
  727. }
  728. public function get_community_member_orderlist()
  729. {
  730. $gpc = I('request.');
  731. $token = $gpc['token'];
  732. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  733. $member_id = $weprogram_token['member_id'];
  734. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  735. if( empty($member_info) )
  736. {
  737. echo json_encode( array('code' => 1) );
  738. die();
  739. }
  740. $community_info = D('Home/Front')->get_member_community_info($member_id);
  741. if( empty($community_info) && $member_info['pickup_id'] > 0 )
  742. {
  743. $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
  744. if(!empty($parent_community_info))
  745. {
  746. $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
  747. }
  748. }
  749. if( empty($community_info) || $community_info['state'] != 1 )
  750. {
  751. echo json_encode( array('code' => 1) );
  752. die();
  753. }
  754. $page = isset($gpc['page']) ? $gpc['page']:'1';
  755. $size = isset($gpc['size']) ? $gpc['size']:'20';
  756. $offset = ($page - 1)* $size;
  757. //begin select
  758. $where = ' and h.head_id = '.$community_info['id'];
  759. //date: that.data.date,
  760. //searchKey: that.data.searchKey,
  761. if( isset($gpc['date']) && !empty($gpc['date']) )
  762. {
  763. }
  764. if( isset($gpc['searchKey']) && !empty($gpc['searchKey']) )
  765. {
  766. $keywords = $gpc['searchKey'];
  767. $mb_order_list = M()->query( "select member_id from ". C('DB_PREFIX')."lionfish_comshop_order
  768. where head_id=".$community_info['id']." and (shipping_tel like '%{$keywords}%' or shipping_name like '%{$keywords}%' ) " );
  769. $member_id_ids = array();
  770. if( !empty($mb_order_list) ){
  771. foreach($mb_order_list as $val)
  772. {
  773. $member_id_ids[] = $val['member_id'];
  774. }
  775. }
  776. if( !empty($member_id_ids) )
  777. {
  778. $member_id_ids_str = implode(',', $member_id_ids);
  779. $where .=" and (m.username like '%{$keywords}%' or h.member_id in({$member_id_ids_str}) ) ";
  780. }else{
  781. $where .=" and (m.username like '%{$keywords}%' ) ";
  782. }
  783. }
  784. $sql = "select h.member_id,h.id ,m.avatar, m.username ,("."select count(order_id) from ".C('DB_PREFIX')."lionfish_comshop_order
  785. where order_status_id =4 and delivery!='express' and delivery!='hexiao' and member_id=m.member_id and head_id= ".$community_info['id'].") as m_count
  786. from ".C('DB_PREFIX')."lionfish_community_history as h left join ".C('DB_PREFIX')."lionfish_comshop_member as m on h.member_id = m.member_id
  787. where 1 {$where}
  788. group by h.member_id order by m_count desc, h.id desc limit {$offset},{$size}";
  789. $list = M()->query($sql);
  790. //ims_lionfish_comshop_order
  791. $need_list = array();
  792. foreach($list as $key => $val)
  793. {
  794. $mb_info_ck = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find();
  795. if( empty($mb_info_ck) )
  796. {
  797. continue;
  798. }
  799. $last_order_info = M('lionfish_comshop_order')->field('shipping_tel,shipping_name')->where( array('head_id' => $community_info['id'],'member_id' =>$val['member_id'] ) )->order('order_id desc')->find();
  800. if( empty($last_order_info) )
  801. {
  802. $val['mobile'] = '未下单';
  803. }else{
  804. $val['mobile'] = $last_order_info['shipping_tel'];
  805. }
  806. $val['shipping_name'] = $last_order_info['shipping_name'];
  807. $order_count = M('lionfish_comshop_order')->where( array('head_id' => $community_info['id'],'member_id' => $val['member_id'],'order_status_id' => 4) )->where("delivery!='express' and delivery!='hexiao'")->count();
  808. //$val['username'] = $member_info['username'];
  809. //$val['avatar'] = $member_info['avatar'];
  810. $val['order_count'] = $order_count;
  811. $list[$key] = $val;
  812. $need_list[$key] = $val;
  813. }
  814. $close_community_delivery_orders = D('Home/Front')->get_config_by_name('close_community_delivery_orders');
  815. if( !empty($need_list) )
  816. {
  817. $list = array();
  818. $i =0;
  819. foreach($need_list as $key => $val)
  820. {
  821. $list[$i] = $val;
  822. $i ++;
  823. }
  824. echo json_encode( array('code' => 0, 'data' => $list , 'close_community_delivery_orders'=>$close_community_delivery_orders ) );
  825. die();
  826. }else {
  827. echo json_encode( array('code' => 1) );
  828. die();
  829. }
  830. }
  831. public function bind_community_info()
  832. {
  833. $gpc = I('request.');
  834. $token = $gpc['token'];
  835. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  836. $member_id = $weprogram_token['member_id'];
  837. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  838. if( empty($member_info) )
  839. {
  840. echo json_encode( array('code' => 1) );
  841. die();
  842. }
  843. $community_info = D('Home/Front')->get_member_community_info($member_id);
  844. if( empty($community_info) || $community_info['state'] != 1 )
  845. {
  846. echo json_encode( array('code' => 1) );
  847. die();
  848. }
  849. $cardname = $gpc['cardname'];
  850. $cardaccount = $gpc['cardaccount'];
  851. $cardno = $gpc['cardno'];
  852. //ims_
  853. //pdo_update('lionfish_community_head', $data, array('id' => $head_info['id']));
  854. $data = array();
  855. $data['bankname'] = $cardname;
  856. $data['bankaccount'] = $cardaccount;
  857. $data['bankusername'] = $cardno;
  858. M('lionfish_community_head_commiss')->where( array('head_id' => $community_info['id']) )->save( $data );
  859. echo json_encode( array('code' => 0) );
  860. die();
  861. }
  862. public function get_community_info()
  863. {
  864. $gpc = I('request.');
  865. $token = $gpc['token'];
  866. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  867. $member_id = $weprogram_token['member_id'];
  868. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  869. if( empty($member_info) )
  870. {
  871. echo json_encode( array('code' => 1) );
  872. die();
  873. }
  874. $community_info = D('Home/Front')->get_member_community_info($member_id);
  875. if( empty($community_info) || $community_info['state'] != 1 )
  876. {
  877. echo json_encode( array('code' => 1) );
  878. die();
  879. }
  880. $community_info['re_id'] = sprintf("%05d", $community_info['id']);
  881. $head_id = $community_info['id'];
  882. //已获佣金情况
  883. $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
  884. //总订单数量
  885. $total_order_count = D('Home/Frontorder')->get_community_head_order_count($head_id);
  886. //待配送 1 1
  887. $wait_send_count = M('lionfish_comshop_order')->where( array('order_status_id' => 1, 'head_id' => $head_id) )->where(" type != 'ignore' ")->count();
  888. //待签收 14 14
  889. $wait_qianshou_count = M('lionfish_comshop_order')->where( array('order_status_id' => 14, 'head_id' => $head_id) )->count();
  890. //待提货 4 4
  891. $wait_tihuo_count = M('lionfish_comshop_order')->where( array('order_status_id' => 4, 'head_id' => $head_id) )->count();
  892. //完成6-》 (6,11)
  893. $has_success_count = M('lionfish_comshop_order')->where( array('order_status_id' => array('in','6,11'), 'head_id' => $head_id) )->count();
  894. //会员数量
  895. $total_member_count = D('Seller/Community')->get_community_head_member_count($head_id);
  896. //预计佣金 state=0
  897. $pre_total_money = M('lionfish_community_head_commiss_order')->where( array('state' => 0,'head_id' => $head_id) )->sum('money');
  898. if( empty($pre_total_money) )
  899. {
  900. $pre_total_money = 0;
  901. }
  902. //退配送费
  903. $refund_shipping_fare = 0;
  904. $refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
  905. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
  906. . " WHERE ogf.order_id = oco.order_id "
  907. . " AND oco.head_id = ".$head_id
  908. . " AND oco.state = 0 "
  909. . " AND oco.add_shipping_fare > 0 ";
  910. $refund_shippings = M()->query($refund_shipping_sql);
  911. if(!empty($refund_shippings)){
  912. $refund_shipping_fare = $refund_shippings[0]['refund_shipping_fare'];
  913. }
  914. $pre_total_money = $pre_total_money - $refund_shipping_fare;
  915. $commission_info['mix_total_money'] = $pre_total_money + $commission_info['money'] + $commission_info['dongmoney'] + $commission_info['getmoney'];
  916. $today_time = strtotime( date('Y-m-d').' 00:00:00' );
  917. //今日订单总数
  918. $today_order_count = M('lionfish_comshop_order')->where("head_id={$head_id} and date_added>={$today_time}")->count();
  919. //今日有效订单
  920. $today_effect_order_count = M('lionfish_comshop_order')->where( "order_status_id not in(3,5,7,12) and head_id={$head_id} and date_added>={$today_time} " )->count();
  921. //1、销售额:团长下面今日订单额度的总和,当日订单总数页面的总和 TODO..
  922. $seven_pay_where = " and head_id ={$head_id} and pay_time >= {$today_time} and order_status_id in (1,4,6,11,14) ";
  923. $seven_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $seven_pay_where);
  924. $head_today_pay_money = empty($seven_pay_money_info['total']) ? 0:$seven_pay_money_info['total'];
  925. $head_today_pay_money = sprintf("%.2f",$head_today_pay_money);
  926. //2、新增会员数:团长新增的用户统计 TODO..
  927. $sql_count = "select count(h.id) as count from ".C('DB_PREFIX').
  928. "lionfish_community_history as h, ".C('DB_PREFIX')."lionfish_comshop_member as m where m.member_id=h.member_id and h.head_id={$head_id} and m.create_time>={$today_time} ";
  929. $today_add_head_member_arr = M()->query($sql_count);
  930. $today_add_head_member = $today_add_head_member_arr[0]['count'];
  931. //3.售后订单(笔):今日团长下面,申请售后的订单
  932. $sql_count = "select count(ref_id) as count from ".C('DB_PREFIX').
  933. "lionfish_comshop_order_refund where head_id={$head_id} and addtime>={$today_time} ";
  934. $today_after_sale_order_count_arr = M()->query($sql_count);
  935. $today_after_sale_order_count = $today_after_sale_order_count_arr[0]['count'];
  936. //4、今日访客:统计今日浏览团长商城的用户数量 TODO..
  937. $sql_count = "select count(id) as count from ".C('DB_PREFIX').
  938. "lionfish_community_history where head_id={$head_id} and addtime>={$today_time} ";
  939. $today_invite_head_member_arr = M()->query($sql_count);
  940. $today_invite_head_member = $today_invite_head_member_arr[0]['count'];
  941. //今日付款人数
  942. $sql_count = "select order_id from ".C('DB_PREFIX')."lionfish_comshop_order where head_id={$head_id} and pay_time>={$today_time} group by member_id ";
  943. $today_pay_order_list = M()->query($sql_count);
  944. $today_pay_order_count = count($today_pay_order_list);
  945. //今日预计佣金
  946. //$today_pre_total_money = M('lionfish_community_head_commiss_order')->where( " state=0 and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
  947. $pre_sql = "SELECT SUM( co.money ) as money "
  948. . "FROM ".C('DB_PREFIX')."lionfish_community_head_commiss_order AS co "
  949. . "LEFT JOIN ".C('DB_PREFIX')."lionfish_comshop_order AS o ON co.order_id = o.order_id"
  950. . " WHERE co.head_id = ".$head_id
  951. . " AND co.addtime >= ".$today_time
  952. . " AND o.order_status_id not in (3,5,7,12) and co.state != 2 ";
  953. $today_pre_total_moneys = M()->query($pre_sql);
  954. if(!empty($today_pre_total_moneys)){
  955. $today_pre_total_money = $today_pre_total_moneys[0]['money'];
  956. }
  957. if(empty($today_pre_total_money))
  958. {
  959. $today_pre_total_money = 0;
  960. }
  961. //退配送费
  962. $today_refund_shipping_fare = 0;
  963. $today_refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
  964. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
  965. . " WHERE ogf.order_id = oco.order_id "
  966. . " AND oco.head_id = ".$head_id
  967. . " AND oco.state = 0 "
  968. . " AND oco.addtime >= '".$today_time."'"
  969. . " AND oco.add_shipping_fare > 0 ";
  970. $today_refund_shippings = M()->query($today_refund_shipping_sql);
  971. if(!empty($today_refund_shippings)){
  972. $today_refund_shipping_fare = $today_refund_shippings[0]['refund_shipping_fare'];
  973. }
  974. $today_pre_total_money = $today_pre_total_money - $today_refund_shipping_fare;
  975. //今日预计佣金+得到佣金
  976. $today_all_total_money = M('lionfish_community_head_commiss_order')->where( "(state=0 or state =1) and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
  977. if(empty($today_all_total_money))
  978. {
  979. $today_all_total_money = 0;
  980. }
  981. $today_all_total_money = sprintf("%.2f", $today_all_total_money);
  982. $month_day = date('Y-m').'-01 00:00:00';
  983. $month_time = strtotime($month_day);
  984. //本月收入 and (state=0 or state =1)
  985. $month_pre_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and (state=0 or state =1) and addtime>={$month_time}" )->sum('money');
  986. if(empty($month_pre_total_money))
  987. {
  988. $month_pre_total_money = 0;
  989. }
  990. /**待确认佣金*/
  991. //$wait_sub_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and state=0" )->sum('money');
  992. $sql = "select sum( co.money ) as money from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  993. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  994. where co.order_goods_id = og.order_goods_id and og.is_refund_state = 0 and co.state = 0 and co.head_id = ".$head_id." order by co.id desc ";
  995. $pre_total_money_list = M()->query($sql);
  996. $wait_sub_total_money = $pre_total_money_list[0]['money'];
  997. if( empty($wait_sub_total_money) )
  998. {
  999. $wait_sub_total_money = 0;
  1000. }
  1001. //提现中
  1002. $dongmoney = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 0) )->sum('money');
  1003. if( empty($dongmoney) )
  1004. {
  1005. $dongmoney = 0 ;
  1006. }
  1007. /**已成功提现金额**/
  1008. $tixian_sucess_money = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 1) )->sum('money');
  1009. if( empty($tixian_sucess_money) )
  1010. {
  1011. $tixian_sucess_money = 0;
  1012. }
  1013. $head_commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('head_commiss_tixianway_yuer');
  1014. $head_commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('head_commiss_tixianway_weixin');
  1015. $head_commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('head_commiss_tixianway_alipay');
  1016. $head_commiss_tixianway_bank = D('Home/Front')->get_config_by_name('head_commiss_tixianway_bank');
  1017. $community_info['head_commiss_tixianway_yuer'] = empty($head_commiss_tixianway_yuer) ? 1 : ($head_commiss_tixianway_yuer == 2 ? 1:0);
  1018. $community_info['head_commiss_tixianway_weixin'] = empty($head_commiss_tixianway_weixin) ? 1 : ($head_commiss_tixianway_weixin == 2 ? 1:0);
  1019. $community_info['head_commiss_tixianway_alipay'] = empty($head_commiss_tixianway_alipay) ? 1 : ($head_commiss_tixianway_alipay == 2 ? 1:0);
  1020. $community_info['head_commiss_tixianway_bank'] = empty($head_commiss_tixianway_bank) ? 1 : ($head_commiss_tixianway_bank == 2 ? 1:0);
  1021. //上一微信真实姓名 lionfish_community_head_tixian_order
  1022. $last_weixin_realname = "";
  1023. //C('DB_PREFIX')
  1024. $last_weixin_info = M('lionfish_community_head_tixian_order')->where( array("member_id={$member_id} and head_id={$head_id} and type=2") )->find();
  1025. if( !empty($last_weixin_info) )
  1026. {
  1027. $last_weixin_realname = $last_weixin_info['bankusername'];
  1028. }
  1029. //上一支付宝账号
  1030. $last_alipay_name = '';
  1031. $last_alipay_account = '';
  1032. $last_alipay_info = M('lionfish_community_head_tixian_order')->where("member_id={$member_id} and head_id={$head_id} and type=3")->find();
  1033. if( !empty($last_alipay_info) )
  1034. {
  1035. $last_alipay_name = $last_alipay_info['bankusername'];
  1036. $last_alipay_account = $last_alipay_info['bankaccount'];
  1037. }
  1038. //上一银行卡信息
  1039. $last_bank_bankname = '';
  1040. $last_bank_account = '';
  1041. $last_bank_name = '';
  1042. $last_bank_info = M('lionfish_community_head_tixian_order')->where( "member_id={$member_id} and head_id={$head_id} and type=4" )->find();
  1043. if( !empty($last_bank_info) )
  1044. {
  1045. $last_bank_bankname = $last_bank_info['bankname'];
  1046. $last_bank_account = $last_bank_info['bankaccount'];
  1047. $last_bank_name = $last_bank_info['bankusername'];
  1048. }
  1049. $community_info['last_weixin_realname'] = $last_weixin_realname;
  1050. $community_info['last_alipay_name'] = $last_alipay_name;
  1051. $community_info['last_alipay_account'] = $last_alipay_account;
  1052. $community_info['last_bank_bankname'] = $last_bank_bankname;
  1053. $community_info['last_bank_account'] = $last_bank_account;
  1054. $community_info['last_bank_name'] = $last_bank_name;
  1055. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1056. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1057. $level_list = array(
  1058. 0 => array('levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money )
  1059. );
  1060. $hd_level_list = M('lionfish_comshop_community_head_level')->where(1)->select();
  1061. if( !empty($hd_level_list) )
  1062. {
  1063. foreach( $hd_level_list as $val )
  1064. {
  1065. $tmp = array();
  1066. $tmp['levelname'] = $val['levelname'];//等级名称
  1067. $tmp['commission'] = $val['commission'];//分佣比例
  1068. $level_list[$val['id']] = $tmp;
  1069. }
  1070. }
  1071. $is_show_head_level = D('Home/Front')->get_config_by_name('is_show_head_level');
  1072. $community_info['is_show_head_level'] = $is_show_head_level;
  1073. $community_info['head_level_info'] = $level_list[ $community_info['level_id'] ];
  1074. // 接龙开关
  1075. $is_open_solitaire = D('Home/Front')->get_config_by_name('is_open_solitaire');
  1076. $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
  1077. //是否显示团长排行, 0不显示,1显示
  1078. $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
  1079. $result = array();
  1080. $result['code'] = 0;
  1081. $result['member_info'] = $member_info;
  1082. $result['community_info'] = $community_info;
  1083. $result['commission_info'] = $commission_info;
  1084. $result['total_order_count'] = $total_order_count;
  1085. $result['total_member_count'] = $total_member_count;
  1086. $result['today_order_count'] = $today_order_count;
  1087. $result['today_effect_order_count'] = $today_effect_order_count;
  1088. $result['today_all_total_money'] = $today_all_total_money;
  1089. $result['today_pay_order_count'] = $today_pay_order_count;
  1090. $result['today_pre_total_money'] = $today_pre_total_money;
  1091. $result['month_pre_total_money'] = $month_pre_total_money;
  1092. $result['pre_total_money'] = $pre_total_money;
  1093. $result['wait_sub_total_money'] = $wait_sub_total_money;
  1094. $result['dongmoney'] = $dongmoney;
  1095. $result['tixian_sucess_money'] = $tixian_sucess_money;
  1096. $result['wait_send_count'] = $wait_send_count;
  1097. $result['wait_qianshou_count'] = $wait_qianshou_count;
  1098. $result['wait_tihuo_count'] = $wait_tihuo_count;
  1099. $result['has_success_count'] = $has_success_count;
  1100. $result['head_today_pay_money'] = $head_today_pay_money;//今日销售额
  1101. $result['today_add_head_member'] = $today_add_head_member;//今日新增会员数
  1102. $result['today_after_sale_order_count'] = $today_after_sale_order_count;//今日售后订单
  1103. $result['today_invite_head_member'] = $today_invite_head_member;//今日访客
  1104. $result['is_show_community_ranking'] = $is_show_community_ranking;//团长排行
  1105. $result['is_open_solitaire'] = $is_open_solitaire;
  1106. $community_tixian_fee = D('Home/Front')->get_config_by_name('community_tixian_fee');
  1107. $community_min_money = D('Home/Front')->get_config_by_name('community_min_money');
  1108. if( empty($community_min_money) )
  1109. {
  1110. $community_min_money = 0;
  1111. }
  1112. if( empty($community_tixian_fee) )
  1113. {
  1114. $community_tixian_fee = 0;
  1115. }
  1116. $result['community_tixian_fee'] = $community_tixian_fee;
  1117. $result['community_min_money'] = $community_min_money;
  1118. $open_community_addhexiaomember = D('Home/Front')->get_config_by_name('open_community_addhexiaomember');
  1119. if( empty($open_community_addhexiaomember) )
  1120. {
  1121. $open_community_addhexiaomember = 0;
  1122. }
  1123. $result['open_community_addhexiaomember'] = $open_community_addhexiaomember;
  1124. //团长等级
  1125. $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
  1126. if( empty($open_community_head_leve) )
  1127. {
  1128. $open_community_head_leve = 0;
  1129. }
  1130. $result['open_community_head_leve'] = $open_community_head_leve;
  1131. $head_commiss_tixian_publish = D('Home/Front')->get_config_by_name('head_commiss_tixian_publish');
  1132. $result['head_commiss_tixian_publish'] = htmlspecialchars_decode( $head_commiss_tixian_publish );
  1133. $is_need_subscript = 0;
  1134. $need_subscript_template = array();
  1135. $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'apply_tixian') )->find();
  1136. if( empty($apply_tixian_info) )
  1137. {
  1138. $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  1139. if( !empty($weprogram_subtemplate_apply_tixian) )
  1140. {
  1141. $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
  1142. }
  1143. }
  1144. if( !empty($need_subscript_template) )
  1145. {
  1146. $is_need_subscript = 1;
  1147. }
  1148. $result['is_need_subscript'] = $is_need_subscript;
  1149. $result['need_subscript_template'] = $need_subscript_template;
  1150. // 分享信息
  1151. $result['shop_index_share_title'] = D('Home/Front')->get_config_by_name('shop_index_share_title');
  1152. $shop_index_share_image = D('Home/Front')->get_config_by_name('shop_index_share_image');
  1153. $result['shop_index_share_image'] = "";
  1154. if($shop_index_share_image) {
  1155. $result['shop_index_share_image'] = tomedia($shop_index_share_image);
  1156. }
  1157. echo json_encode( $result );
  1158. die();
  1159. }
  1160. //begin
  1161. /**
  1162. 获取团长的下级列表接口
  1163. **/
  1164. public function get_head_child_headlist()
  1165. {
  1166. $gpc = I('request.');
  1167. $_GPC = I('request.');
  1168. $token = $gpc['token'];
  1169. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1170. $member_id = $weprogram_token['member_id'];
  1171. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1172. if( empty($member_info) )
  1173. {
  1174. echo json_encode( array('code' => 1) );
  1175. die();
  1176. }
  1177. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1178. if( empty($community_info) || $community_info['state'] != 1 )
  1179. {
  1180. echo json_encode( array('code' => 1) );
  1181. die();
  1182. }
  1183. $head_id = $community_info['id'];
  1184. //...
  1185. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  1186. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  1187. $offset = ($page - 1)* $size;
  1188. //begin select
  1189. //$where = ' and head_id = '.$head_id;
  1190. $level = isset($_GPC['level']) ? $_GPC['level']: 1;
  1191. $level_1_ids = array();
  1192. $level_2_ids = array();
  1193. $level_3_ids = array();
  1194. $head_id_arr = array($head_id);
  1195. if( $level == 1 )
  1196. {
  1197. $list = array();
  1198. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1199. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1200. $list = M()->query($sql);
  1201. foreach( $list as $vv )
  1202. {
  1203. $level_1_ids[] = $vv['id'];
  1204. }
  1205. }else if( $level == 2 )
  1206. {
  1207. $list = array();
  1208. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1209. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1210. $list1 = M()->query($sql);
  1211. if( !empty($list1) )
  1212. {
  1213. foreach( $list1 as $vv )
  1214. {
  1215. $level_1_ids[] = $vv['id'];
  1216. }
  1217. $level_sql2 =" select * from ".C('DB_PREFIX').
  1218. "lionfish_community_head where
  1219. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1220. where agent_id ={$head_id} order by id desc ) order by id desc ";
  1221. $list2 = M()->query($level_sql2);
  1222. if( !empty($list2) || !empty($level_1_ids))
  1223. {
  1224. foreach( $list2 as $vv )
  1225. {
  1226. $level_2_ids[] = $vv['id'];
  1227. }
  1228. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  1229. if(!empty($level_2_ids))
  1230. {
  1231. foreach($level_2_ids as $vv)
  1232. {
  1233. $need_ids[] = $vv;
  1234. }
  1235. }
  1236. $sql =" select * from ".C('DB_PREFIX').
  1237. "lionfish_community_head where
  1238. id in (".implode(',', $need_ids ).") order by id desc limit {$offset},{$size}";
  1239. $list = M()->query($sql);
  1240. }
  1241. }
  1242. }else if( $level == 3 ){
  1243. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
  1244. where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
  1245. $list1 = M()->query($sql);
  1246. if( !empty($list1) )
  1247. {
  1248. foreach( $list1 as $vv )
  1249. {
  1250. $level_1_ids[] = $vv['id'];
  1251. }
  1252. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  1253. $level_sql2 =" select * from ".C('DB_PREFIX').
  1254. "lionfish_community_head where
  1255. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1256. where agent_id ={$head_id} order by id desc ) order by id desc ";
  1257. $list2 = M()->query($level_sql2);
  1258. if( !empty($list2) || !empty($level_1_ids))
  1259. {
  1260. foreach( $list2 as $vv )
  1261. {
  1262. $level_2_ids[] = $vv['id'];
  1263. }
  1264. if(!empty($level_2_ids))
  1265. {
  1266. foreach($level_2_ids as $vv)
  1267. {
  1268. $need_ids[] = $vv;
  1269. }
  1270. }
  1271. }
  1272. $level_sql3 =" select * from ".C('DB_PREFIX').
  1273. "lionfish_community_head where
  1274. agent_id in (".implode(',', $need_ids).") order by id desc ";
  1275. $list3 = M()->query($level_sql3);
  1276. if( !empty($list3) )
  1277. {
  1278. foreach( $list3 as $vv )
  1279. {
  1280. $level_3_ids[] = $vv['id'];
  1281. }
  1282. if(!empty($level_3_ids))
  1283. {
  1284. foreach($level_3_ids as $vv)
  1285. {
  1286. $need_ids[] = $vv;
  1287. }
  1288. }
  1289. }
  1290. $level_sql3 =" select * from ".C('DB_PREFIX').
  1291. "lionfish_community_head where id in (".implode(',',$need_ids).") order by id desc limit {$offset},{$size}";
  1292. $list = M()->query($level_sql3);
  1293. }
  1294. }
  1295. //---------等级
  1296. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1297. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1298. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1299. $list_default = array(
  1300. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1301. );
  1302. $community_head_level = array_merge($list_default, $community_head_level);
  1303. $level_id_to_name = array( 0=> empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname );
  1304. foreach($community_head_level as $kk => $vv)
  1305. {
  1306. $level_id_to_name[$vv['id']] = $vv['levelname'];
  1307. }
  1308. //---------等级
  1309. $level_list = array();
  1310. $need_list = array();
  1311. if( !empty($list) ){
  1312. foreach($list as $key => $val)
  1313. {
  1314. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id'] ) )->find();
  1315. $val['level_name'] = $level_id_to_name[ $val['level_id'] ];
  1316. $val['avatar'] = $mb_info['avatar'];
  1317. $val['username'] = $mb_info['username'];
  1318. $val['apptime'] = date('Y-m-d H:i:s', $val['apptime']);
  1319. $need_list[$key] = $val;
  1320. }
  1321. }
  1322. if( !empty($need_list) )
  1323. {
  1324. echo json_encode( array('code' => 0, 'data' => $need_list) );
  1325. die();
  1326. }else {
  1327. echo json_encode( array('code' => 1) );
  1328. die();
  1329. }
  1330. }
  1331. /**
  1332. 获取团长分销账户信息情况
  1333. **/
  1334. public function get_head_distribute_info()
  1335. {
  1336. $gpc = I('request.');
  1337. $_GPC = I('request.');
  1338. $token = $gpc['token'];
  1339. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1340. $member_id = $weprogram_token['member_id'];
  1341. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1342. if( empty($member_info) )
  1343. {
  1344. echo json_encode( array('code' => 1) );
  1345. die();
  1346. }
  1347. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1348. if( empty($community_info) || $community_info['state'] != 1 )
  1349. {
  1350. echo json_encode( array('code' => 1) );
  1351. die();
  1352. }
  1353. $head_id = $community_info['id'];
  1354. $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
  1355. if( empty($open_community_head_leve) )
  1356. {
  1357. $open_community_head_leve = 0;
  1358. }
  1359. //总收入 wait_money
  1360. //lionfish_community_head_commiss_order
  1361. /**总收入 0 1 **/
  1362. $total_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
  1363. if( empty($total_money) )
  1364. {
  1365. $total_money = 0;
  1366. }
  1367. //tuijian commiss
  1368. //待确认
  1369. $tixian_wait_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=0" )->sum('money');
  1370. if( empty($tixian_wait_money) )
  1371. {
  1372. $tixian_wait_money = 0;
  1373. }
  1374. //已确认
  1375. $tixian_success_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
  1376. if( empty($tixian_success_money) )
  1377. {
  1378. $tixian_success_money = 0;
  1379. }
  1380. //下级团长数量
  1381. $level_count1 = 0;
  1382. $level_count2 = 0;
  1383. $level_count3 = 0;
  1384. $level_count1 = M('lionfish_community_head')->where( array('agent_id' => $head_id ) )->count();
  1385. if( empty($level_count1) || $level_count1 == 0 )
  1386. {
  1387. $level_count1 = 0;
  1388. }else{
  1389. $level_sql2 =" select count(1) as count from ".C('DB_PREFIX').
  1390. "lionfish_community_head where
  1391. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1392. where agent_id ={$head_id} ) ";
  1393. $level_count2_arr = M()->query($level_sql2);
  1394. $level_count2 = $level_count2_arr[0]['count'];
  1395. if( empty($level_count2) || $level_count2 == 0 )
  1396. {
  1397. $level_count2 = 0;
  1398. }else{
  1399. $level_sqllist2 =" select id from ".C('DB_PREFIX').
  1400. "lionfish_community_head where
  1401. agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
  1402. where agent_id ={$head_id} ) ";
  1403. $level_list2 = M()->query($level_sqllist2);
  1404. if( !empty($level_list2) )
  1405. {
  1406. $level_arr2 = array();
  1407. foreach( $level_list2 as $vvv )
  1408. {
  1409. $level_arr2[] = $vvv['id'];
  1410. }
  1411. $level_sql3 =" select count(1) as count from ".C('DB_PREFIX').
  1412. "lionfish_community_head where agent_id in (".implode(',',$level_arr2).") ";
  1413. $level_count3_arr = M()->query( $level_sql3 );
  1414. $level_count3 = $level_count3_arr[0]['count'];
  1415. if( empty($level_count3) || $level_count3 == 0 )
  1416. {
  1417. $level_count3 = 0;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. $need_data = array();
  1423. $need_data['open_community_head_leve'] = $open_community_head_leve;
  1424. $need_data['total_money'] = $total_money;
  1425. $need_data['wait_money'] = sprintf("%.2f",$tixian_wait_money);
  1426. $need_data['success_money'] = sprintf("%.2f",$tixian_success_money);
  1427. $need_data['level_count1'] = $level_count1;
  1428. $need_data['level_count2'] = $level_count1 + $level_count2 ;
  1429. $need_data['level_count3'] = $level_count1 + $level_count2 + $level_count3;
  1430. echo json_encode( array('code' => 0, 'data' => $need_data ) );
  1431. die();
  1432. }
  1433. /**
  1434. 获取团长分销明细
  1435. **/
  1436. public function get_head_distribute_order()
  1437. {
  1438. $gpc = I('request.');
  1439. $_GPC = I('request.');
  1440. $token = $gpc['token'];
  1441. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1442. $member_id = $weprogram_token['member_id'];
  1443. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1444. if( empty($member_info) )
  1445. {
  1446. echo json_encode( array('code' => 1) );
  1447. die();
  1448. }
  1449. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1450. if( empty($community_info) || $community_info['state'] != 1 )
  1451. {
  1452. echo json_encode( array('code' => 1) );
  1453. die();
  1454. }
  1455. $head_id = $community_info['id'];
  1456. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  1457. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  1458. $offset = ($page - 1)* $size;
  1459. $where = ' and head_id = '.$head_id;
  1460. $type = isset($_GPC['type']) ? $_GPC['type']: '';
  1461. $level = isset($_GPC['level']) ? $_GPC['level']: 0;
  1462. if( empty($type) )
  1463. {
  1464. $where .= " and type in ('commiss','tuijian')";
  1465. }
  1466. if( $level > 0 )
  1467. {
  1468. //level
  1469. $where .= " and level=".$level;
  1470. }
  1471. //commiss
  1472. $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head_commiss_order
  1473. where 1 {$where} order by id desc limit {$offset},{$size}";
  1474. $list = M()->query($sql);
  1475. $status_list = M('lionfish_comshop_order_status')->select();
  1476. $status_arr = array();
  1477. foreach($status_list as $vv)
  1478. {
  1479. $status_arr[ $vv['order_status_id'] ] = $vv['name'];
  1480. }
  1481. $need_list = array();
  1482. foreach($list as $key => $val)
  1483. {
  1484. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  1485. $child_head = M('lionfish_community_head')->where( array('id' => $val['child_head_id'] ) )->find();
  1486. $val['child_head_name'] = $child_head['head_name'];
  1487. $val['community_name'] = $child_head['community_name'];
  1488. if( $val['type'] == 'commiss')
  1489. {
  1490. $order_info = M('lionfish_comshop_order')->field('order_num_alias,order_status_id')
  1491. ->where( array('order_id' => $val['order_id'] ) )->find();
  1492. $val['order_num_alias'] = $order_info['order_num_alias'];
  1493. $val['order_status'] = $status_arr[ $order_info['order_status_id'] ];
  1494. }
  1495. $need_list[$key] = $val;
  1496. }
  1497. if( !empty($need_list) )
  1498. {
  1499. echo json_encode( array('code' => 0, 'data' => $need_list) );
  1500. die();
  1501. }else {
  1502. echo json_encode( array('code' => 1) );
  1503. die();
  1504. }
  1505. }
  1506. //end
  1507. public function tixian_community_info()
  1508. {
  1509. $gpc = I('request.');
  1510. $token = $gpc['token'];
  1511. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1512. $member_id = $weprogram_token['member_id'];
  1513. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1514. if( empty($member_info) )
  1515. {
  1516. echo json_encode( array('code' => 1) );
  1517. die();
  1518. }
  1519. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1520. if( empty($community_info) || $community_info['state'] != 1 )
  1521. {
  1522. echo json_encode( array('code' => 1) );
  1523. die();
  1524. }
  1525. $head_id = $community_info['id'];
  1526. $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
  1527. $tixian_money = $gpc['tixian_money'];
  1528. $type = isset($gpc['type']) ? $gpc['type'] : 0;//0 沿用原来的逻辑 1余额 2 微信 3 支付宝 4 银行
  1529. $bankname = isset($gpc['bankname']) ? $gpc['bankname'] : ''; //银行名称
  1530. $bankaccount = isset($gpc['bankaccount']) ? $gpc['bankaccount'] : '';//卡号,支付宝账号 使用该字段
  1531. $bankusername = isset($gpc['bankusername']) ? $gpc['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
  1532. $service_charge = D('Home/Front')->get_config_by_name('community_tixian_fee');
  1533. if($commission_info['money'] >= $tixian_money )
  1534. {
  1535. $data = array();
  1536. $data['member_id'] = $member_id;
  1537. $data['head_id'] = $head_id;
  1538. $data['money'] = floatval($tixian_money);
  1539. $data['state'] = 0;
  1540. $data['type'] = $type;
  1541. $data['bankname'] = $bankname;
  1542. $data['bankaccount'] = $bankaccount;
  1543. $data['bankusername'] = $bankusername;
  1544. $data['service_charge'] = round( ($tixian_money * $service_charge) /100,2);
  1545. $data['shentime'] = 0;
  1546. $data['addtime'] = time();
  1547. M('lionfish_community_head_tixian_order')->add($data);
  1548. M()->execute("update ".C('DB_PREFIX')."lionfish_community_head_commiss set money=money - {$tixian_money},dongmoney=dongmoney+{$tixian_money}
  1549. where head_id={$head_id} ");
  1550. echo json_encode( array('code' => 0) );
  1551. die();
  1552. }else{
  1553. echo json_encode( array('code'=>1) );
  1554. die();
  1555. }
  1556. }
  1557. public function sub_community_head()
  1558. {
  1559. $gpc = I('request.');
  1560. $token = $gpc['token'];
  1561. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1562. $member_id = $weprogram_token['member_id'];
  1563. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1564. if( empty($member_info) )
  1565. {
  1566. echo json_encode( array('code' => 1) );
  1567. die();
  1568. }
  1569. $province_name = $gpc['province_name'];
  1570. $city_name = $gpc['city_name'];
  1571. $area_name = $gpc['area_name'];
  1572. $country_name = $gpc['country_name'];
  1573. $lon_lat = $gpc['lon_lat'];
  1574. $lon_lat_arr = explode(',', $lon_lat);
  1575. $wechat = $gpc['wechat'];
  1576. $province_info = D('Home/Front')->get_area_ninfo_by_name($province_name);
  1577. $province_id = $province_info['id'];
  1578. $city_info = D('Home/Front')->get_area_ninfo_by_name($city_name);
  1579. $city_id = $city_info['id'];
  1580. $area_info = D('Home/Front')->get_area_ninfo_by_name($area_name);
  1581. $area_id = $area_info['id'];
  1582. $country_info = D('Home/Front')->get_area_ninfo_by_name($country_name);
  1583. $country_id = $country_info['id'];
  1584. $addr_detail = $gpc['addr_detail'];
  1585. $community_name = $gpc['community_name'];
  1586. $mobile = $gpc['mobile'];
  1587. $head_name = $gpc['head_name'];
  1588. $community_id = isset($gpc['community_id']) && intval($gpc['community_id']) > 0 ? $gpc['community_id'] : 0;
  1589. $data = array();
  1590. $data['member_id'] = $member_id;
  1591. $data['community_name'] = $community_name;
  1592. $data['head_name'] = $head_name;
  1593. $data['head_mobile'] = $mobile;
  1594. $data['province_id'] = $province_id;
  1595. $data['city_id'] = $city_id;
  1596. $data['country_id'] = $country_id;
  1597. $data['area_id'] = $area_id;
  1598. $data['address'] = $addr_detail;
  1599. $data['lon'] = $lon_lat_arr[0];
  1600. $data['lat'] = $lon_lat_arr[1];
  1601. $data['state'] = 0;
  1602. $data['apptime'] = time();
  1603. $data['addtime'] = time();
  1604. $data['wechat'] = $wechat;
  1605. $head_info = D('Home/Front')->get_member_community_info($member_id);
  1606. $parent_head_id = 0;
  1607. if( $member_info['share_id'] > 0 )
  1608. {
  1609. $parent_head_info = D('Home/Front')->get_member_community_info($member_info['share_id']);
  1610. if( !empty($parent_head_info) )
  1611. {
  1612. $parent_head_id = $parent_head_info['id'];
  1613. }
  1614. }
  1615. $data['agent_id'] = $parent_head_id;
  1616. if( $community_id > 0 )
  1617. {
  1618. $data['agent_id'] = $community_id;
  1619. }
  1620. if( empty($head_info) )
  1621. {
  1622. $head_id = M('lionfish_community_head')->add($data);
  1623. }else{
  1624. unset($data['uniacid']);
  1625. unset($data['addtime']);
  1626. M('lionfish_community_head')->where( array('id' => $head_info['id']) )->save($data);
  1627. $head_id = $head_info['id'];
  1628. }
  1629. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('member_id' =>$member_id,'head_id' => $head_id ) )->find();
  1630. if( empty($head_commiss_info) )
  1631. {
  1632. $datas = array();
  1633. $datas['member_id'] = $member_id;
  1634. $datas['head_id'] = $head_id;
  1635. $datas['money'] = 0;
  1636. $datas['dongmoney'] = 0;
  1637. $datas['getmoney'] = 0;
  1638. $datas['bankname'] = '';
  1639. $datas['bankaccount'] = '';
  1640. $datas['bankusername'] = '';
  1641. $datas['share_avatar'] = '';
  1642. $datas['share_wxcode'] = '';
  1643. $datas['share_title'] = '';
  1644. $datas['share_desc'] = '';
  1645. M('lionfish_community_head_commiss')->add( $datas );
  1646. }
  1647. echo json_encode( array('code' => 0) );
  1648. die();
  1649. }
  1650. /**
  1651. * 获取城市列表
  1652. */
  1653. public function get_city_list()
  1654. {
  1655. $gpc = I('request.');
  1656. $token = $gpc['token'];
  1657. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1658. $member_id = $weprogram_token['member_id'];
  1659. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1660. if( empty($member_info) )
  1661. {
  1662. //echo json_encode( array('code' => 1) );
  1663. //die();
  1664. }
  1665. $city_ids_Arr = M('lionfish_community_head')->field('city_id')->order('city_id asc')->select();
  1666. $city_ids = array();
  1667. foreach ($city_ids_Arr as $k => $val) {
  1668. $city_ids[] = $val['city_id'];
  1669. }
  1670. $city_ids_str = implode(',', $city_ids);
  1671. $city_list = M('lionfish_comshop_area')->where( array('id' => array('in', $city_ids_str) ) )->select();
  1672. // {
  1673. // "districtCode": "152900",
  1674. // "districtLevel": "CITY",
  1675. // "parentDistrictCode": "150000",
  1676. // "districtName": "阿拉善盟",
  1677. // "firstLetter": "A",
  1678. // "serviceStatus": "N"
  1679. // }
  1680. $city_arr = array();
  1681. foreach ($city_list as $key => $value) {
  1682. $city_arr[$key]["city_id"] = $value["id"];
  1683. $city_arr[$key]["districtCode"] = $value["code"];
  1684. $city_arr[$key]["districtLevel"] = "CITY";
  1685. $city_arr[$key]["parentDistrictCode"] = $value["code"];
  1686. $city_arr[$key]["districtName"] = $value["name"];
  1687. $city_arr[$key]["firstLetter"] = $this->getFirstCharter($value["name"]);
  1688. $city_arr[$key]["serviceStatus"] = "N";
  1689. }
  1690. echo json_encode( array('code' => 0, 'data' => $city_arr) );
  1691. die();
  1692. }
  1693. /**
  1694. * 获取首字母
  1695. * @param [type] $str [description]
  1696. * @return [type] [description]
  1697. */
  1698. function getFirstCharter($str)
  1699. {
  1700. if (empty($str)) {
  1701. return '';
  1702. }
  1703. $fchar = ord($str{0});
  1704. if ($fchar >= ord('A') && $fchar <= ord('z'))
  1705. return strtoupper($str{0});
  1706. $s1 = iconv('UTF-8', 'gb2312', $str);
  1707. $s2 = iconv('gb2312', 'UTF-8', $s1);
  1708. $s = $s2 == $str ? $s1 : $str;
  1709. $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
  1710. if ($asc >= -20319 && $asc <= -20284)
  1711. return 'A';
  1712. if ($asc >= -20283 && $asc <= -19776)
  1713. return 'B';
  1714. if ($asc >= -19775 && $asc <= -19219)
  1715. return 'C';
  1716. if ($asc >= -19218 && $asc <= -18711)
  1717. return 'D';
  1718. if ($asc >= -18710 && $asc <= -18527)
  1719. return 'E';
  1720. if ($asc >= -18526 && $asc <= -18240)
  1721. return 'F';
  1722. if ($asc >= -18239 && $asc <= -17923)
  1723. return 'G';
  1724. if ($asc >= -17922 && $asc <= -17418)
  1725. return 'H';
  1726. if ($asc >= -17417 && $asc <= -16475)
  1727. return 'J';
  1728. if ($asc >= -16474 && $asc <= -16213)
  1729. return 'K';
  1730. if ($asc >= -16212 && $asc <= -15641)
  1731. return 'L';
  1732. if ($asc >= -15640 && $asc <= -15166)
  1733. return 'M';
  1734. if ($asc >= -15165 && $asc <= -14923)
  1735. return 'N';
  1736. if ($asc >= -14922 && $asc <= -14915)
  1737. return 'O';
  1738. if ($asc >= -14914 && $asc <= -14631)
  1739. return 'P';
  1740. if ($asc >= -14630 && $asc <= -14150)
  1741. return 'Q';
  1742. if ($asc >= -14149 && $asc <= -14091)
  1743. return 'R';
  1744. if ($asc >= -14090 && $asc <= -13319)
  1745. return 'S';
  1746. if ($asc >= -13318 && $asc <= -12839)
  1747. return 'T';
  1748. if ($asc >= -12838 && $asc <= -12557)
  1749. return 'W';
  1750. if ($asc >= -12556 && $asc <= -11848)
  1751. return 'X';
  1752. if ($asc >= -11847 && $asc <= -11056)
  1753. return 'Y';
  1754. if ($asc >= -11055 && $asc <= -10247)
  1755. return 'Z';
  1756. return null;
  1757. }
  1758. /**
  1759. * 获取申请页面
  1760. */
  1761. public function get_apply_page()
  1762. {
  1763. $info = M('lionfish_comshop_config')->field( 'value' )->where( array('name' => 'communityhead_apply_page') )->find();
  1764. if(!empty($info['value'])){
  1765. echo json_encode( array('code' => 0, 'data' => htmlspecialchars_decode(htmlspecialchars_decode($info['value']))) );
  1766. die();
  1767. }else{
  1768. echo json_encode( array('code' => 1 ));
  1769. die();
  1770. }
  1771. }
  1772. public function check_head_subscriptapply()
  1773. {
  1774. $_GPC = I('request.');
  1775. $token = $_GPC['token'];
  1776. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1777. $member_id = $weprogram_token['member_id'];
  1778. $is_need_subscript = 0;
  1779. $need_subscript_template = array();
  1780. //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
  1781. $apply_community_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_community' ) )->find();
  1782. if( empty($apply_community_info) )
  1783. {
  1784. $weprogram_subtemplate_apply_community = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
  1785. if( !empty($weprogram_subtemplate_apply_community) )
  1786. {
  1787. $need_subscript_template['apply_community'] = $weprogram_subtemplate_apply_community;
  1788. }
  1789. }
  1790. $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_tixian' ) )->find();
  1791. if( empty($apply_tixian_info) )
  1792. {
  1793. $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  1794. if( !empty($weprogram_subtemplate_apply_tixian) )
  1795. {
  1796. $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
  1797. }
  1798. }
  1799. if( !empty($need_subscript_template) )
  1800. {
  1801. $is_need_subscript = 1;
  1802. }
  1803. echo json_encode( array('code' => 0, 'is_need_subscript' => $is_need_subscript,'need_subscript_template' => $need_subscript_template ) );
  1804. die();
  1805. }
  1806. //----------begin ----------------
  1807. /**
  1808. * 团长设置页面团长资料
  1809. */
  1810. public function get_head_info()
  1811. {
  1812. $_GPC = I('request.');
  1813. $token = $_GPC['token'];
  1814. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1815. $member_id = $weprogram_token['member_id'];
  1816. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1817. if( empty($member_info) )
  1818. {
  1819. echo json_encode( array('code' => 1) );
  1820. die();
  1821. }
  1822. $id = $_GPC['id'];
  1823. if($id > 0)
  1824. {
  1825. $item = M('lionfish_community_head')->where( array('id' => $id ) )->find();
  1826. $item['province_name'] = D('Seller/Area')->get_area_info($item['province_id']);
  1827. $item['city_name'] = D('Seller/Area')->get_area_info($item['city_id']);
  1828. $item['area_name'] = D('Seller/Area')->get_area_info($item['area_id']);
  1829. $item['country_name'] = D('Seller/Area')->get_area_info($item['country_id']);
  1830. if( $item['member_id'] > 0)
  1831. {
  1832. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('head_id' => $item['id'],'member_id' =>$item['member_id'] ) )->find();
  1833. if( !empty($head_commiss_info) )
  1834. {
  1835. $item['bankname'] = $head_commiss_info['bankname'];
  1836. $item['bankaccount'] = $head_commiss_info['bankaccount'];
  1837. $item['bankusername'] = $head_commiss_info['bankusername'];
  1838. $item['share_wxcode'] = tomedia($head_commiss_info['share_wxcode']);
  1839. }
  1840. }
  1841. $item['member_info'] = $member_info;
  1842. $item['rest'] = D('Seller/Communityhead')->is_community_rest($id);
  1843. $item['re_id'] = sprintf("%05d", $item['id']);
  1844. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  1845. $close_community_reset_btn = D('Home/Front')->get_config_by_name('close_community_reset_btn');
  1846. if(empty($delivery_type_tuanz))
  1847. {
  1848. $delivery_type_tuanz = 2;
  1849. }
  1850. $item['delivery_type_tuanz'] = $delivery_type_tuanz;
  1851. $item['close_reset_btn'] = $close_community_reset_btn;
  1852. if(!empty($item)){
  1853. echo json_encode( array('code' => 0, 'data' => $item) );
  1854. die();
  1855. }else{
  1856. // 无数据
  1857. echo json_encode( array('code' => 2 ));
  1858. die();
  1859. }
  1860. }
  1861. }
  1862. /**
  1863. * 团长设置休息状态
  1864. */
  1865. public function set_head_rest()
  1866. {
  1867. $_GPC = I('request.');
  1868. $token = $_GPC['token'];
  1869. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1870. $member_id = $weprogram_token['member_id'];
  1871. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1872. if( empty($member_info) )
  1873. {
  1874. echo json_encode( array('code' => 1) );
  1875. die();
  1876. }
  1877. $head_id = $_GPC['id'];
  1878. $rest = $_GPC['rest'];
  1879. if($head_id > 0){
  1880. $result = M('lionfish_community_head')->where( array('id' => $head_id) )->save( array('rest' => $rest) );
  1881. if(!empty($result)){
  1882. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1883. die();
  1884. }else{
  1885. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1886. die();
  1887. }
  1888. }else{
  1889. // id不存在
  1890. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1891. die();
  1892. }
  1893. }
  1894. /**
  1895. * 团长信息修改
  1896. */
  1897. public function modify_head_info()
  1898. {
  1899. $_GPC = I('request.');
  1900. $token = $_GPC['token'];
  1901. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1902. $member_id = $weprogram_token['member_id'];
  1903. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1904. if( empty($member_info) )
  1905. {
  1906. echo json_encode( array('code' => 1) );
  1907. die();
  1908. }
  1909. $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
  1910. $data = array();
  1911. $data['head_name'] = $_GPC['head_name'];
  1912. $data['head_mobile'] = $_GPC['head_mobile'];
  1913. $data['is_modify_shipping_method'] = $_GPC['is_modify_shipping_method'];//是否自定义配送开关。0跟随系统,1开启,2关闭
  1914. $data['is_modify_shipping_fare'] = $_GPC['is_modify_shipping_fare'];//是否自定义配送费,0跟随系统,1自定义
  1915. $data['shipping_fare'] = $_GPC['shipping_fare'];// 自定义配送费
  1916. if($head_id > 0){
  1917. $rs = M('lionfish_community_head')->where( array('id' => $head_id, 'member_id' => $member_id) )->save( $data );
  1918. $commiss_data = array();
  1919. $commiss_data['share_wxcode'] = $_GPC['share_wxcode'];
  1920. if($commiss_data['share_wxcode']){
  1921. $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $commiss_data );
  1922. }
  1923. if(!empty($rs)){
  1924. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1925. die();
  1926. }else{
  1927. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1928. die();
  1929. }
  1930. }else{
  1931. // id不存在
  1932. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1933. die();
  1934. }
  1935. }
  1936. /**
  1937. * 团长信息修改
  1938. */
  1939. public function modify_head_commiss()
  1940. {
  1941. $_GPC = I('request.');
  1942. $token = $_GPC['token'];
  1943. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1944. $member_id = $weprogram_token['member_id'];
  1945. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1946. if( empty($member_info) )
  1947. {
  1948. echo json_encode( array('code' => 1) );
  1949. die();
  1950. }
  1951. $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
  1952. $data = array();
  1953. $data['bankname'] = $_GPC['bankname'];
  1954. $data['bankaccount'] = $_GPC['bankaccount'];
  1955. $data['bankusername'] = $_GPC['bankusername'];
  1956. // $data['address'] = $_GPC['address'];
  1957. // $data['lon'] = $_GPC['lon'];
  1958. // $data['lat'] = $_GPC['lat'];
  1959. // $data['state'] = $_GPC['state'];
  1960. if($head_id > 0){
  1961. $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $data );
  1962. if(!empty($rs)){
  1963. echo json_encode( array('code' => 0, 'data' => '修改成功'));
  1964. die();
  1965. }else{
  1966. echo json_encode( array('code' => 2, 'data' => '修改失败'));
  1967. die();
  1968. }
  1969. }else{
  1970. // id不存在
  1971. echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
  1972. die();
  1973. }
  1974. }
  1975. public function community_index_shareqrcode()
  1976. {
  1977. $_GPC = I('request.');
  1978. $token = $_GPC['token'];
  1979. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1980. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1981. {
  1982. $member_id = 0;
  1983. }else{
  1984. $member_id = $weprogram_token['member_id'];
  1985. }
  1986. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1987. if( empty($member_info) )
  1988. {
  1989. echo json_encode( array('code' => 1) );
  1990. die();
  1991. }
  1992. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1993. if( empty($community_info) || $community_info['state'] != 1 )
  1994. {
  1995. echo json_encode( array('code' => 1) );
  1996. die();
  1997. }
  1998. $community_id = $community_info['id'];
  1999. $community_index_shareqrcode_json = D('Home/Front')->get_config_by_name('community_index_shareqrcode_'.$community_id );
  2000. $community_index_shareqrcode_arr = unserialize($community_index_shareqrcode_json);
  2001. $load_new = false;
  2002. if( empty($community_index_shareqrcode_arr) )
  2003. {
  2004. $load_new = true;
  2005. }else {
  2006. if( $community_index_shareqrcode_arr['endtime'] < time() )
  2007. {
  2008. $load_new = true;
  2009. }
  2010. }
  2011. if( $load_new || true )
  2012. {
  2013. $goods_model = D('Home/Pingoods');
  2014. $qrcode_image = $goods_model->_get_index_wxqrcode($member_id,$community_id,'jpg');
  2015. $data = array();
  2016. $data['image_path'] = '/'.$qrcode_image;
  2017. $ed_time = time() + 300;
  2018. $js_arr = array('endtime' => $ed_time,'image_path' => $data['image_path'] );
  2019. $cd_key = 'community_index_shareqrcode_'.$community_id;
  2020. D('Seller/Config')->update( array( $cd_key => serialize($js_arr) ) );
  2021. }else{
  2022. $data = array();
  2023. $data['image_path'] ='/'.$community_index_shareqrcode_arr['image_path'];
  2024. }
  2025. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  2026. $data['image_path'] = $shop_domain.$data['image_path'];
  2027. $result = array('code' => 0, 'qrcode' => $data['image_path'] );
  2028. echo json_encode($result);
  2029. die();
  2030. }
  2031. /**
  2032. * 团长排行榜
  2033. */
  2034. public function community_ranking_list(){
  2035. $_GPC = I('request.');
  2036. $token = $_GPC['token'];
  2037. $type = $_GPC['type'];
  2038. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2039. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2040. {
  2041. $member_id = 0;
  2042. }else{
  2043. $member_id = $weprogram_token['member_id'];
  2044. }
  2045. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  2046. if( empty($member_info) )
  2047. {
  2048. echo json_encode( array('code' => 1, 'mgs'=> '请登录') );
  2049. die();
  2050. }
  2051. $community_info = D('Home/Front')->get_member_community_info($member_id);
  2052. if( empty($community_info) || $community_info['state'] != 1 )
  2053. {
  2054. echo json_encode( array('code' => 1, 'mgs'=> '您不是团长,无法查看') );
  2055. die();
  2056. }
  2057. $begin_time = 0;
  2058. $end_time = 0;
  2059. if($type == 1){//今日
  2060. $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()));
  2061. $end_time = strtotime(date('Y-m-d'.'00:00:00',time()+3600*24));
  2062. }else if($type == 2){//昨日
  2063. $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()-3600*24));
  2064. $end_time = strtotime(date('Y-m-d'.'00:00:00',time()));
  2065. }else if($type == 3){//上周
  2066. $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))));
  2067. $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'))));
  2068. }else if($type == 4){//上月
  2069. //上月开始时间
  2070. $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))));
  2071. //上月结束时间
  2072. $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))));
  2073. }
  2074. $list = array();
  2075. $sql = " select * from ( "
  2076. . " select co.head_id,count(distinct(co.order_id)) as order_count, "
  2077. . " sum(co.money) as money "
  2078. . " from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co "
  2079. . " left join ".C('DB_PREFIX')."lionfish_comshop_order as o "
  2080. . " on co.order_id = o.order_id "
  2081. . " left join ".C('DB_PREFIX')."lionfish_community_head as h "
  2082. . " on co.head_id = h.id "
  2083. . " where co.addtime >= ".$begin_time." and co.addtime <= ".$end_time
  2084. . " and o.order_status_id not in (3,5,7,12) and co.state != 2 and h.state = 1 and h.enable = 1 "
  2085. . " group by co.head_id) t "
  2086. . " order by money desc "
  2087. . " limit 20 ";
  2088. //echo $sql;
  2089. $list = M()->query($sql);
  2090. foreach($list as $k=>$v){
  2091. $community_head = M('lionfish_community_head')->where( array('id' => $v['head_id']) )->find();
  2092. $list[$k]['community_name'] = $community_head['community_name'];
  2093. $member_info = M('lionfish_comshop_member')->field('avatar')->where( array('member_id' => $community_head['member_id']) )->find();
  2094. $list[$k]['avatar'] = $member_info['avatar'];
  2095. }
  2096. $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
  2097. //是否显示团长排行, 0不显示,1显示
  2098. $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
  2099. echo json_encode(array('code' => 0,'data'=>$list , 'is_show_community_ranking' => $is_show_community_ranking ));
  2100. die();
  2101. }
  2102. //----------end----------------------
  2103. }