DistributionController.class.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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 DistributionController extends CommonController {
  16. public function main()
  17. {
  18. echo json_encode( array('code' =>0) );
  19. die();
  20. }
  21. public function get_instruct()
  22. {
  23. $communitymember_apply_page = D('Home/Front')->get_config_by_name('communitymember_apply_page');
  24. $communitymember_apply_page = htmlspecialchars_decode($communitymember_apply_page);
  25. echo json_encode( array('code' => 0, 'content' => $communitymember_apply_page) );
  26. die();
  27. }
  28. /**
  29. 提交申请表单
  30. @param 注意,申请表单的时候,需要判断是否满足其他条件了。如果已经满足了,那么就可以直接申请了
  31. 提交参数:{token:'xxx', data: [{type:input,name:'姓名',value="123"},{type:radio,name:'姓名',value="123"}] }
  32. **/
  33. public function sub_distribut_form()
  34. {
  35. $_GPC = I('request.');
  36. $token = $_GPC['token'];
  37. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  38. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  39. {
  40. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  41. die();
  42. }
  43. $member_id = $weprogram_token['member_id'];
  44. $data = json_decode( htmlspecialchars_decode( $_GPC['data']) ,true);
  45. $commiss_formcontent = serialize( $data );
  46. //M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
  47. //判断是否需要审核
  48. $commiss_become_condition = D('Home/Front')->get_config_by_name('commiss_become_condition');
  49. if( empty($commiss_become_condition) || $commiss_become_condition == 0 )
  50. {
  51. //不需要审核,那么直接升级为分销了
  52. //M('lionfish_comshop_member')->where( array('share_id' => $member_id, 'agentid' => 0 ) )->save( array('agentid' => $member_id ) );
  53. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
  54. D('Home/Commission')->become_commiss_member($member_id);
  55. echo json_encode( array('code' =>0, 'msg' =>'提交成功') );
  56. die();
  57. }else{
  58. //需要审核,成为分销,待审核状态
  59. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('comsiss_flag' => 1,'is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
  60. //将未 挪动上级的会员归到当前会员的下级去
  61. M('lionfish_comshop_member')->where( array('share_id' => $member_id ) )->save( array('agentid' => $member_id ) );
  62. echo json_encode( array('code' =>0, 'msg' =>'申请成功,平台将尽快审核') );
  63. die();
  64. }
  65. echo json_encode( array('code' =>0, 'msg' =>'提交成功') );
  66. die();
  67. }
  68. /**
  69. 会员申请分销按钮确认
  70. **/
  71. public function sub_commission_info()
  72. {
  73. $_GPC = I('request.');
  74. $token = $_GPC['token'];
  75. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  76. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  77. {
  78. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  79. die();
  80. }
  81. $member_id = $weprogram_token['member_id'];
  82. //开始判断
  83. $share_member_count = M('lionfish_comshop_member')->where( "share_id={$member_id} and (agentid =0 or agentid={$member_id})" )->count();
  84. //1、是否需要分享
  85. $commiss_sharemember_need = D('Home/Front')->get_config_by_name('commiss_sharemember_need');
  86. if( !empty($commiss_sharemember_need) && $commiss_sharemember_need == 1 )
  87. {
  88. // 2、分享多少人才能成为分销
  89. $commiss_share_member_update = D('Home/Front')->get_config_by_name('commiss_share_member_update');
  90. if( !empty($commiss_share_member_update) && $commiss_share_member_update > 0 )
  91. {
  92. if( $share_member_count < $commiss_share_member_update )
  93. {
  94. $del = $commiss_share_member_update - $share_member_count;
  95. echo json_encode( array('code' =>1 , 'msg' => '分享人数还差'.$del.'人','del_count' => $del ) );
  96. die();
  97. }
  98. }
  99. }
  100. $member_info = M('lionfish_comshop_member')->field('is_writecommiss_form,comsiss_flag,comsiss_state')->where( array('member_id' =>$member_id ) )->find();
  101. // 3、commiss_biaodan_need 是否需要表单
  102. $commiss_biaodan_need = D('Home/Front')->get_config_by_name('commiss_biaodan_need');
  103. if( !empty($commiss_biaodan_need) && $commiss_biaodan_need == 1 )
  104. {
  105. if( $member_info['is_writecommiss_form'] != 1)
  106. {
  107. echo json_encode( array('code' =>1 , 'msg' => '您未填写表单!' ) );
  108. die();
  109. }
  110. }
  111. //4判断是否需要审核
  112. $commiss_become_condition = D('Home/Front')->get_config_by_name('commiss_become_condition');
  113. if( empty($commiss_become_condition) || $commiss_become_condition == 0 )
  114. {
  115. //不需要审核,那么直接升级为分销了
  116. D('Home/Commission')->become_commiss_member($member_id);
  117. echo json_encode( array('code' =>0, 'msg' =>'申请成功!') );
  118. die();
  119. }else{
  120. //需要审核,成为分销,待审核状态
  121. D('Home/Commission')->become_wait_commiss_member($member_id);
  122. echo json_encode( array('code' =>0, 'msg' =>'申请成功,平台将尽快审核') );
  123. die();
  124. }
  125. }
  126. public function get_parent_agent_info_bymemberid()
  127. {
  128. $_GPC = I('request.');
  129. $member_id = $_GPC['member_id'];
  130. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  131. if( empty($member_info) )
  132. {
  133. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  134. die();
  135. }
  136. $data_result = array('parent_username' => '','parent_telephone' => '','share_username' => '','share_telephone' => '' );
  137. if( $member_info['agentid'] > 0 )
  138. {
  139. $parent_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['agentid'] ) )->find();
  140. $data_result['parent_username'] = $parent_mb['username'];//上级姓名
  141. $data_result['parent_telephone'] = $parent_mb['telephone'];//上级电话
  142. }
  143. if( $member_info['share_id'] > 0 )
  144. {
  145. $share_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['share_id'] ) )->find();
  146. $data_result['share_username'] = $share_mb['username'];//上级姓名
  147. $data_result['share_telephone'] = $share_mb['telephone'];//上级电话
  148. }
  149. echo json_encode( array('code' => 0, 'data' => $data_result) );
  150. die();
  151. }
  152. public function get_parent_agent_info()
  153. {
  154. $_GPC = I('request.');
  155. $token = $_GPC['token'];
  156. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  157. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  158. {
  159. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  160. die();
  161. }
  162. $member_id = $weprogram_token['member_id'];
  163. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  164. if( empty($member_info) )
  165. {
  166. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  167. die();
  168. }
  169. $data_result = array('parent_username' => '','parent_telephone' => '','share_username' => '','share_telephone' => '' );
  170. if( $member_info['agentid'] > 0 )
  171. {
  172. $parent_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['agentid'] ) )->find();
  173. $data_result['parent_username'] = $parent_mb['username'];//上级姓名
  174. $data_result['parent_telephone'] = $parent_mb['telephone'];//上级电话
  175. }
  176. if( $member_info['share_id'] > 0 )
  177. {
  178. $share_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['share_id'] ) )->find();
  179. $data_result['share_username'] = $share_mb['username'];//上级姓名
  180. $data_result['share_telephone'] = $share_mb['telephone'];//上级电话
  181. }
  182. echo json_encode( array('code' => 0, 'data' => $data_result) );
  183. die();
  184. }
  185. /**
  186. 会员分销提现 提交接口
  187. **/
  188. public function tixian_sub()
  189. {
  190. $_GPC = I('request.');
  191. $token = $_GPC['token'];
  192. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  193. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  194. {
  195. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  196. die();
  197. }
  198. $member_id = $weprogram_token['member_id'];
  199. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  200. if( empty($member_info) )
  201. {
  202. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  203. die();
  204. }
  205. if($member_info['comsiss_flag'] != 1 )
  206. {
  207. echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
  208. die();
  209. }
  210. if($member_info['comsiss_state'] != 1 )
  211. {
  212. echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
  213. die();
  214. }
  215. $result = array('code' => 1,'msg' => '提现失败');
  216. $member_commiss = M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->find();
  217. $datas = array();
  218. $datas['money'] = $_GPC['money'];
  219. $money = $datas['money'];
  220. $type = $_GPC['type'];// 1余额 2 微信 3 支付宝 4 银行
  221. $bankname = isset($_GPC['bankname']) ? $_GPC['bankname'] : ''; //银行名称
  222. $bankaccount = isset($_GPC['bankaccount']) ? $_GPC['bankaccount'] : '';//卡号,支付宝账号 使用该字段
  223. $bankusername = isset($_GPC['bankusername']) ? $_GPC['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
  224. $commiss_money_limit = D('Home/Front')->get_config_by_name('commiss_min_tixian_money');
  225. if(!empty($commiss_money_limit) && $commiss_money_limit >0)
  226. {
  227. if($member_commiss['money'] < $commiss_money_limit)
  228. {
  229. $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
  230. echo json_encode($result);
  231. die();
  232. }
  233. }
  234. if($money > 0 && $money <= $member_commiss['money'])
  235. {
  236. //判断提现手续费,+ 判断提现金额免审直接到账
  237. $service_charge = D('Home/Front')->get_config_by_name('commiss_tixian_bili');
  238. $data = array();
  239. $data['member_id'] = $member_id;
  240. $data['uniacid'] = 0;
  241. $data['money'] = $money;
  242. $data['service_charge'] = $service_charge;
  243. $data['service_charge_money'] = round( ($money * $service_charge) /100 ,2);
  244. $data['state'] = 0;
  245. $data['shentime'] = 0;
  246. $data['type'] = $type;
  247. $data['bankname'] = $bankname;
  248. $data['bankaccount'] = $bankaccount;
  249. $data['bankusername'] = $bankusername;
  250. $data['addtime'] = time();
  251. M('lionfish_comshop_member_tixian_order')->add( $data );
  252. $com_arr = array();
  253. $com_arr['money'] = $member_commiss['money'] - $money;
  254. $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
  255. M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->setInc('money',-$money );
  256. M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->setInc('dongmoney',$money );
  257. $result['code'] = 0;
  258. //commiss_tixian_reviewed 0 , 1
  259. $commiss_tixian_reviewed = D('Home/Front')->get_config_by_name('commiss_tixian_reviewed');
  260. if(empty($commiss_tixian_reviewed) || $commiss_tixian_reviewed == 0)
  261. {
  262. //手动
  263. } else if( !empty($commiss_tixian_reviewed) && $commiss_tixian_reviewed == 1 ){
  264. //自动
  265. }
  266. }
  267. echo json_encode($result);
  268. die();
  269. }
  270. /**
  271. 提现记录
  272. **/
  273. public function tixian_record()
  274. {
  275. $_GPC = I('request.');
  276. $token = $_GPC['token'];
  277. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  278. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  279. {
  280. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  281. die();
  282. }
  283. $member_id = $weprogram_token['member_id'];
  284. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  285. if( empty($member_info) )
  286. {
  287. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  288. die();
  289. }
  290. if($member_info['comsiss_flag'] != 1 )
  291. {
  292. echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
  293. die();
  294. }
  295. if($member_info['comsiss_state'] != 1 )
  296. {
  297. echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
  298. die();
  299. }
  300. $per_page = 10;
  301. $page = isset($_GPC['page']) ? $_GPC['page']:1;
  302. $offset = ($page - 1) * $per_page;
  303. $list = array();
  304. $list = M('lionfish_comshop_member_tixian_order')->where( array('member_id' => $member_id ) )->order( 'addtime desc' )->limit($offset,$per_page )->select();
  305. foreach($list as $key => $val)
  306. {
  307. $val['addtime'] = date('Y-m-d H:i', $val['addtime']);
  308. $list[$key] = $val;
  309. }
  310. if( !empty($list) )
  311. {
  312. echo json_encode( array('code' =>0, 'data'=>$list) );
  313. die();
  314. }else{
  315. echo json_encode( array('code' => 1) );
  316. die();
  317. }
  318. }
  319. private function get_member_next_child($member_id)
  320. {
  321. $level = D('Home/Front')->get_config_by_name('commiss_level');// isset($_GPC['level']) ? $_GPC['level']: 1;
  322. $level_1_ids = array();
  323. $level_2_ids = array();
  324. $level_3_ids = array();
  325. $member_id_arr = array($member_id);
  326. $where = "";
  327. $need_count = 0;
  328. //commiss_level
  329. if( $level == 1 )
  330. {
  331. $list = array();
  332. $need_count = M('lionfish_comshop_member')->where( "agentid in (".implode(',', $member_id_arr).")" )->count();
  333. }else if( $level == 2 )
  334. {
  335. $list = array();
  336. $list1 = M('lionfish_comshop_member')->field('member_id')->where( "agentid in (".implode(',', $member_id_arr).")" )->order('member_id desc')->select();
  337. if( !empty($list1) )
  338. {
  339. foreach( $list1 as $vv )
  340. {
  341. $level_1_ids[] = $vv['member_id'];
  342. }
  343. $level_sql2 =" select member_id from ".C('DB_PREFIX').
  344. "lionfish_comshop_member where
  345. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  346. where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
  347. $list2 = M()->query($level_sql2);
  348. if( !empty($list2) )
  349. {
  350. foreach( $list2 as $vv )
  351. {
  352. $level_2_ids[] = $vv['member_id'];
  353. }
  354. }
  355. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  356. if(!empty($level_2_ids))
  357. {
  358. foreach($level_2_ids as $vv)
  359. {
  360. $need_ids[] = $vv;
  361. }
  362. }
  363. if(!empty($need_ids))
  364. {
  365. $sql =" select count(member_id) as count from ".C('DB_PREFIX').
  366. "lionfish_comshop_member where 1 {$where} and
  367. member_id in (".implode(',', $need_ids ).") ";
  368. $need_count_arr = M()->query($sql);
  369. $need_count = $need_count_arr[0]['count'];
  370. }
  371. }
  372. }else if( $level == 3 ){
  373. $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  374. where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
  375. $list1 = M()->query($sql);
  376. if( !empty($list1) )
  377. {
  378. foreach( $list1 as $vv )
  379. {
  380. $level_1_ids[] = $vv['member_id'];
  381. }
  382. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  383. $level_sql2 =" select member_id from ".C('DB_PREFIX').
  384. "lionfish_comshop_member where
  385. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  386. where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
  387. $list2 = M()->query($level_sql2);
  388. if( !empty($list2) )
  389. {
  390. foreach( $list2 as $vv )
  391. {
  392. $level_2_ids[] = $vv['member_id'];
  393. }
  394. if(!empty($level_2_ids))
  395. {
  396. foreach($level_2_ids as $vv)
  397. {
  398. $need_ids[] = $vv;
  399. }
  400. }
  401. }
  402. $level_sql3 =" select * from ".C('DB_PREFIX').
  403. "lionfish_comshop_member where
  404. agentid in (".implode(',', $need_ids).") order by member_id desc ";
  405. $list3 = M()->query($level_sql3);
  406. if( !empty($list3) )
  407. {
  408. foreach( $list3 as $vv )
  409. {
  410. $level_3_ids[] = $vv['member_id'];
  411. }
  412. if(!empty($level_3_ids))
  413. {
  414. foreach($level_3_ids as $vv)
  415. {
  416. $need_ids[] = $vv;
  417. }
  418. }
  419. }
  420. $level_sql3 =" select count(member_id) as count from ".C('DB_PREFIX').
  421. "lionfish_comshop_member where 1 {$where} and member_id in (".implode(',',$need_ids).") ";
  422. $need_count_arr = M()->query($level_sql3);
  423. $need_count = $need_count_arr[0]['count'];
  424. }
  425. }
  426. return $need_count;
  427. }
  428. /**
  429. 获取会员粉丝列表接口
  430. **/
  431. public function get_member_fanslist()
  432. {
  433. $_GPC = I('request.');
  434. $token = $_GPC['token'];
  435. $keyword = $_GPC['keyword'];
  436. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  437. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  438. {
  439. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  440. die();
  441. }
  442. $member_id = $weprogram_token['member_id'];
  443. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  444. if( empty($member_info) )
  445. {
  446. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  447. die();
  448. }
  449. //...
  450. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  451. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  452. $offset = ($page - 1)* $size;
  453. //begin select keyword
  454. $level = D('Home/Front')->get_config_by_name('commiss_level');// isset($_GPC['level']) ? $_GPC['level']: 1;
  455. $level_1_ids = array();
  456. $level_2_ids = array();
  457. $level_3_ids = array();
  458. $member_id_arr = array($member_id);
  459. $where = "";
  460. if( !empty($keyword) )
  461. {
  462. $where .= " and ( username like '%{$keyword}%' or telephone like '%{$keyword}%' ) ";
  463. }
  464. //commiss_level ( "share_id={$member_id} and (agentid =0 or agentid={$member_id} )" )
  465. $list = array();
  466. $sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_member
  467. where 1 {$where} and (share_id = {$member_id} and (agentid =0 or agentid={$member_id} ) ) order by member_id desc limit {$offset},{$size}";
  468. $list = M()->query($sql);
  469. foreach( $list as $vv )
  470. {
  471. $level_1_ids[$vv['id']] = $vv['id'];
  472. }
  473. $level_list = array();
  474. $need_list = array();
  475. if( !empty($list) )
  476. {
  477. foreach($list as $key => $val)
  478. {
  479. $val['child_level'] = 1;
  480. $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  481. $need_list[$key] = $val;
  482. }
  483. }
  484. $bg_time = strtotime( date('Y-m-d').' 00:00:00');
  485. $yes_time = $bg_time - 86400;
  486. if( !empty($need_list) )
  487. {
  488. echo json_encode( array('code' => 0, 'data' => $need_list ) );
  489. die();
  490. }else {
  491. echo json_encode( array('code' => 1 ) );
  492. die();
  493. }
  494. }
  495. /**
  496. 获取团长的下级列表接口
  497. **/
  498. public function get_head_child_headlist()
  499. {
  500. $_GPC = I('request.');
  501. $token = $_GPC['token'];
  502. $keyword = $_GPC['keyword'];
  503. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  504. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  505. {
  506. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  507. die();
  508. }
  509. $member_id = $weprogram_token['member_id'];
  510. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  511. if( empty($member_info) )
  512. {
  513. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  514. die();
  515. }
  516. if($member_info['comsiss_flag'] != 1 )
  517. {
  518. echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
  519. die();
  520. }
  521. if($member_info['comsiss_state'] != 1 )
  522. {
  523. echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
  524. die();
  525. }
  526. //...
  527. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  528. $size = isset($_GPC['size']) ? $_GPC['size']:'20';
  529. $offset = ($page - 1)* $size;
  530. $level = D('Home/Front')->get_config_by_name('commiss_level');
  531. $level_1_ids = array();
  532. $level_2_ids = array();
  533. $level_3_ids = array();
  534. $member_id_arr = array($member_id);
  535. $where = "";
  536. if( !empty($keyword) )
  537. {
  538. $where .= " and ( username like '%{$keyword}%' or telephone like '%{$keyword}%' ) ";
  539. }
  540. //commiss_level
  541. if( $level == 1 )
  542. {
  543. $list = array();
  544. $sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_member
  545. where 1 {$where} and agentid in (".implode(',', $member_id_arr).") order by member_id desc limit {$offset},{$size}";
  546. $list = M()->query($sql);
  547. foreach( $list as $vv )
  548. {
  549. $level_1_ids[$vv['id']] = $vv['id'];
  550. }
  551. }else if( $level == 2 )
  552. {
  553. $list = array();
  554. $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  555. where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
  556. $list1 = M()->query($sql);
  557. if( !empty($list1) )
  558. {
  559. foreach( $list1 as $vv )
  560. {
  561. $level_1_ids[$vv['member_id']] = $vv['member_id'];
  562. }
  563. $level_sql2 =" select member_id from ".C('DB_PREFIX').
  564. "lionfish_comshop_member where
  565. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  566. where agentid = {$member_id} order by member_id desc ) order by member_id desc ";
  567. $list2 = M()->query($level_sql2);
  568. if( !empty($list2) || !empty($list1) )
  569. {
  570. foreach( $list2 as $vv )
  571. {
  572. $level_2_ids[$vv['member_id']] = $vv['member_id'];
  573. }
  574. }
  575. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  576. if(!empty($level_2_ids))
  577. {
  578. foreach($level_2_ids as $vv)
  579. {
  580. $need_ids[] = $vv;
  581. }
  582. }
  583. if(!empty($need_ids))
  584. {
  585. $sql =" select * from ".C('DB_PREFIX').
  586. "lionfish_comshop_member where 1 {$where} and
  587. member_id in (".implode(',', $need_ids ).") order by member_id desc limit {$offset},{$size}";
  588. $list = M()->query($sql);
  589. }
  590. }
  591. }else if( $level == 3 ){
  592. $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  593. where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
  594. $list1 = M()->query($sql);
  595. if( !empty($list1) )
  596. {
  597. foreach( $list1 as $vv )
  598. {
  599. $level_1_ids[$vv['member_id']] = $vv['member_id'];
  600. }
  601. $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
  602. $level_sql2 =" select * from ".C('DB_PREFIX').
  603. "lionfish_comshop_member where
  604. agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
  605. where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
  606. $list2 = M()->query($level_sql2);
  607. if( !empty($list2) )
  608. {
  609. foreach( $list2 as $vv )
  610. {
  611. $level_2_ids[$vv['member_id']] = $vv['member_id'];
  612. }
  613. if(!empty($level_2_ids))
  614. {
  615. foreach($level_2_ids as $vv)
  616. {
  617. $need_ids[] = $vv;
  618. }
  619. }
  620. }
  621. $level_sql3 =" select member_id from ".C('DB_PREFIX').
  622. "lionfish_comshop_member where
  623. agentid in (".implode(',', $need_ids).") order by member_id desc ";
  624. $list3 = M()->query($level_sql3);
  625. if( !empty($list3) )
  626. {
  627. foreach( $list3 as $vv )
  628. {
  629. $level_3_ids[$vv['member_id']] = $vv['member_id'];
  630. }
  631. if(!empty($level_3_ids))
  632. {
  633. foreach($level_3_ids as $vv)
  634. {
  635. $need_ids[] = $vv;
  636. }
  637. }
  638. }
  639. $level_sql3 =" select * from ".C('DB_PREFIX').
  640. "lionfish_comshop_member where 1 {$where} and member_id in (".implode(',',$need_ids).") order by member_id desc limit {$offset},{$size}";
  641. $list = M()->query($level_sql3);
  642. }
  643. }
  644. $level_list = array();
  645. $need_list = array();
  646. if( !empty($list) )
  647. {
  648. foreach($list as $key => $val)
  649. {
  650. //member_id
  651. $val['child_level'] = 1;
  652. if( isset($level_2_ids[$val['member_id']]) )
  653. {
  654. $val['child_level'] = 2;
  655. }
  656. else if( isset($level_3_ids[$val['member_id']]) )
  657. {
  658. $val['child_level'] = 3;
  659. }
  660. $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  661. $need_list[$key] = $val;
  662. }
  663. }
  664. $bg_time = strtotime( date('Y-m-d').' 00:00:00');
  665. $yes_time = $bg_time - 86400;
  666. $today_member_count = M('lionfish_comshop_member')->where( "agentid={$member_id} and create_time>={$bg_time}" )->count();
  667. $yes_member_count = M('lionfish_comshop_member')->where( "agentid={$member_id} and create_time>={$yes_time} and create_time< {$bg_time}" )->count();
  668. if( !empty($need_list) )
  669. {
  670. echo json_encode( array('code' => 0, 'data' => $need_list , 'today_member_count'=>$today_member_count,'yes_member_count'=>$yes_member_count) );
  671. die();
  672. }else {
  673. echo json_encode( array('code' => 1, 'today_member_count'=>$today_member_count,'yes_member_count'=>$yes_member_count) );
  674. die();
  675. }
  676. }
  677. /**
  678. 获取会员分销基础数据
  679. **/
  680. public function get_commission_info()
  681. {
  682. $_GPC = I('request.');
  683. $token = $_GPC['token'];
  684. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  685. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  686. {
  687. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  688. die();
  689. }
  690. $member_id = $weprogram_token['member_id'];
  691. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  692. if( empty($member_info) )
  693. {
  694. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  695. die();
  696. }
  697. if($member_info['comsiss_flag'] != 1 )
  698. {
  699. echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
  700. die();
  701. }
  702. if($member_info['comsiss_state'] != 1 )
  703. {
  704. echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
  705. die();
  706. }
  707. $parent_info = '';
  708. //上级信息
  709. if($member_info['agentid'] > 0 ) {
  710. $parent_res = D('Home/Commission')->get_parent_info($member_info['agentid']);
  711. $parent_info['member_id'] = $parent_res['member_id'];
  712. $parent_info['username'] = $parent_res['username'];
  713. }
  714. //最小提现金额
  715. $commiss_min_tixian_money = D('Home/Front')->get_config_by_name('commiss_min_tixian_money');
  716. if( empty($commiss_min_tixian_money) )
  717. {
  718. $commiss_min_tixian_money = 0;
  719. }
  720. $commiss_tixian_bili = D('Home/Front')->get_config_by_name('commiss_tixian_bili');
  721. if( empty($commiss_tixian_bili) )
  722. {
  723. $commiss_tixian_bili = 0;
  724. }
  725. //C('DB_PREFIX')
  726. $member_commiss = M('lionfish_comshop_member_commiss')->where( array('member_id' =>$member_id ) )->find();
  727. $member_commiss['commiss_min_tixian_money'] = $commiss_min_tixian_money;//最小提现金额, 0标识不限制
  728. $member_commiss['commiss_tixian_bili'] = $commiss_tixian_bili;
  729. $member_commiss['total_commiss_money'] = $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney'];
  730. //订单数量
  731. $order_count = M('lionfish_comshop_member_commiss_order')->where( array('member_id' =>$member_id ) )->count();
  732. //会员数量
  733. $member_commiss['order_count'] = $order_count;
  734. $member_commiss['member_count'] = $this->get_member_next_child($member_id);
  735. $commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('commiss_tixianway_yuer');
  736. $commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('commiss_tixianway_weixin');
  737. $commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('commiss_tixianway_alipay');
  738. $commiss_tixianway_bank = D('Home/Front')->get_config_by_name('commiss_tixianway_bank');
  739. $member_commiss['commiss_tixianway_yuer'] = empty($commiss_tixianway_yuer) ? 1 : ($commiss_tixianway_yuer == 2 ? 1:0);
  740. $member_commiss['commiss_tixianway_weixin'] = empty($commiss_tixianway_weixin) ? 1 : ($commiss_tixianway_weixin == 2 ? 1:0);
  741. $member_commiss['commiss_tixianway_alipay'] = empty($commiss_tixianway_alipay) ? 1 : ($commiss_tixianway_alipay == 2 ? 1:0);
  742. $member_commiss['commiss_tixianway_bank'] = empty($commiss_tixianway_bank) ? 1 : ($commiss_tixianway_bank == 2 ? 1:0);
  743. //share_id agentid
  744. $member_commiss['share_name'] = '';
  745. if( $member_info['share_id'] > 0 )
  746. {
  747. $mbshare_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $member_info['share_id']) )->find();
  748. $member_commiss['share_name'] = $mbshare_info['username'];
  749. }
  750. //上一微信真实姓名
  751. $last_weixin_realname = "";
  752. $last_weixin_info = M('lionfish_comshop_member_tixian_order')->where( "member_id={$member_id} and type=2" )->find();
  753. if( !empty($last_weixin_info) )
  754. {
  755. $last_weixin_realname = $last_weixin_info['bankusername'];
  756. }
  757. //上一支付宝账号
  758. $last_alipay_name = '';
  759. $last_alipay_account = '';
  760. $last_alipay_info = M('lionfish_comshop_member_tixian_order')->where( "member_id={$member_id} and type=3" )->find();
  761. if( !empty($last_alipay_info) )
  762. {
  763. $last_alipay_name = $last_alipay_info['bankusername'];
  764. $last_alipay_account = $last_alipay_info['bankaccount'];
  765. }
  766. //上一银行卡信息
  767. $last_bank_bankname = '';
  768. $last_bank_account = '';
  769. $last_bank_name = '';
  770. $last_bank_info = M('lionfish_comshop_member_tixian_order')->where( "member_id={$member_id} and type=4" )->find();
  771. if( !empty($last_bank_info) )
  772. {
  773. $last_bank_bankname = $last_bank_info['bankname'];
  774. $last_bank_account = $last_bank_info['bankaccount'];
  775. $last_bank_name = $last_bank_info['bankusername'];
  776. }
  777. $member_commiss['last_weixin_realname'] = $last_weixin_realname;
  778. $member_commiss['last_alipay_name'] = $last_alipay_name;
  779. $member_commiss['last_alipay_account'] = $last_alipay_account;
  780. $member_commiss['last_bank_bankname'] = $last_bank_bankname;
  781. $member_commiss['last_bank_account'] = $last_bank_account;
  782. $member_commiss['last_bank_name'] = $last_bank_name;
  783. $commiss_tixian_publish = D('Home/Front')->get_config_by_name('commiss_tixian_publish');
  784. $member_commiss['commiss_tixian_publish'] = htmlspecialchars_decode( $commiss_tixian_publish );
  785. $member_commiss['total_money'] = sprintf('%.2f', $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney']);
  786. $is_need_subscript = 0;
  787. $need_subscript_template = array();
  788. $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'apply_tixian') )->find();
  789. if( empty($apply_tixian_info) )
  790. {
  791. $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  792. if( !empty($weprogram_subtemplate_apply_tixian) )
  793. {
  794. $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
  795. }
  796. }
  797. if( !empty($need_subscript_template) )
  798. {
  799. $is_need_subscript = 1;
  800. }
  801. echo json_encode( array('code' =>0,'data' => $member_commiss ,'is_need_subscript' => $is_need_subscript, 'need_subscript_template' => $need_subscript_template, 'parent_info'=>$parent_info ) );
  802. die();
  803. }
  804. /**
  805. 获取分销订单
  806. **/
  807. public function listorder_list()
  808. {
  809. $_GPC = I('request.');
  810. $token = $_GPC['token'];
  811. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  812. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  813. {
  814. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  815. die();
  816. }
  817. $member_id = $weprogram_token['member_id'];
  818. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  819. if( empty($member_info) )
  820. {
  821. echo json_encode( array('code' => 1, 'msg' => '会员不存在') );
  822. die();
  823. }
  824. if($member_info['comsiss_flag'] != 1 )
  825. {
  826. echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
  827. die();
  828. }
  829. if($member_info['comsiss_state'] != 1 )
  830. {
  831. echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
  832. die();
  833. }
  834. $per_page = 6;
  835. $page = isset($_GPC['page']) ? $_GPC['page']:1;
  836. $offset = ($page - 1) * $per_page;
  837. $list = array();
  838. $where = '';
  839. $state = isset($_GPC['state']) ? $_GPC['state']: -1;
  840. //state
  841. if($state >=0)
  842. {
  843. $where .= ' and mco.state = '.$state;
  844. }
  845. $commiss_level_num = D('Home/Front')->get_config_by_name('commiss_level');
  846. $where .= ' and mco.level <= '.$commiss_level_num;
  847. $url = D('Home/Front')->get_config_by_name('shop_domain');
  848. //$this->state = $state;
  849. $sql = 'select mco.level, mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_id,o.order_num_alias,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.has_refund_money,og.has_refund_quantity, og.name,og.price,og.goods_images,og.order_goods_id,mco.store_id,m.username as uname from '
  850. .C('DB_PREFIX')."lionfish_comshop_member_commiss_order as mco , ".C('DB_PREFIX')."lionfish_comshop_order_goods as og,
  851. ".C('DB_PREFIX')."lionfish_comshop_order as o ,
  852. ".C('DB_PREFIX')."lionfish_comshop_member as m
  853. where mco.order_id=og.order_id and mco.order_id = o.order_id and mco.order_goods_id=og.order_goods_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  854. $list = M()->query($sql);
  855. $status_arr = D('Seller/Order')->get_order_status_name();
  856. //rela_goodsoption_valueid
  857. foreach($list as $key =>$val)
  858. {
  859. $val['total'] = round($val['total'],2);
  860. $val['money'] = round($val['money'],2);
  861. $val['price'] = sprintf("%.2f", $val['price']);
  862. $val['status_name'] = $status_arr[$val['order_status_id']];
  863. $val['addtime'] = date('Y-m-d', $val['addtime']);
  864. if( !empty($val['goods_images']))
  865. {
  866. $goods_images = $url. '/'.resize($val['goods_images'],400,400);
  867. if(is_array($goods_images))
  868. {
  869. $val['goods_images'] = $val['goods_images'];
  870. }else{
  871. $val['goods_images']= $url.'/'.resize($val['goods_images'],400,400) ;
  872. }
  873. }else{
  874. $val['goods_images']= '';
  875. }
  876. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $val['order_goods_id'] ) )->select();
  877. foreach($order_option_list as $option)
  878. {
  879. $val['option_str'][] = $option['value'];
  880. }
  881. if( !isset($val['option_str']) )
  882. {
  883. $val['option_str'] = '';
  884. }else{
  885. $val['option_str'] = implode(',', $val['option_str']);
  886. }
  887. $val['old_commision'] = $val['money'];
  888. $val['del_commision'] = 0;
  889. $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->where( "order_goods_id=".$val['order_goods_id'] )->select();
  890. //level
  891. if( !empty($order_goods_refund_list) )
  892. {
  893. $kvbal_total_back_head_orderbuycommiss = 0;//合计退掉佣金
  894. foreach( $order_goods_refund_list as $kvval )
  895. {
  896. if($val['level'] == 1)
  897. $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_1'];
  898. if($val['level'] == 2)
  899. $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_2'];
  900. if($val['level'] == 3)
  901. $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_3'];
  902. }
  903. $val['del_commision'] = $kvbal_total_back_head_orderbuycommiss;
  904. $val['old_commision'] += $val['del_commision'];
  905. }
  906. $list[$key] = $val;
  907. }
  908. if(empty($list))
  909. {
  910. echo json_encode( array('code' => 1) );
  911. die();
  912. }else {
  913. echo json_encode( array('code' => 0, 'data' => $list) );
  914. die();
  915. }
  916. }
  917. /**
  918. 获取会员分享海报
  919. **/
  920. public function get_haibao()
  921. {
  922. $_GPC = I('request.');
  923. $token = $_GPC['token'];
  924. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  925. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  926. {
  927. echo json_encode( array('code' => 1,'msg' =>'请先登录') );
  928. die();
  929. }
  930. $goods_model = D('Home/Pingoods');
  931. $member_id = $weprogram_token['member_id'];
  932. $last_community = M('lionfish_community_history')->field('head_id')->where( array('member_id' => $member_id) )->order('addtime desc')->find();
  933. if( empty($last_community) )
  934. {
  935. $last_community = M('lionfish_community_head')->field('id as head_id')->where(" state=1 and enable=1 and rest=0 ")->order('id desc ')->find();
  936. }
  937. $head_id =0;
  938. if( !empty($last_community) )
  939. {
  940. $head_id = $last_community['head_id'];
  941. }
  942. //TODO....寻找上一个社区,生成海报。测试png 跟jpg背景的情况,反过来解决 首页 跟商品海报的问题。
  943. $member_info = M('lionfish_comshop_member')->field('commiss_qrcode,avatar,username')->where( array('member_id' => $member_id ) )->find();
  944. $commiss_qrcode = '';
  945. if( empty($member_info['commiss_qrcode']))
  946. {
  947. $commiss_qrcode = $goods_model->_get_index_wxqrcode($member_id,$head_id);
  948. $avatar = $goods_model->get_commission_user_avatar($member_info['avatar'], $member_id,5);
  949. $result = $goods_model->get_commission_index_share_image($head_id,$commiss_qrcode,$avatar, $member_info['username']);
  950. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('commiss_qrcode' => $result['full_path']) );
  951. echo json_encode( array('code' => 0, 'commiss_qrcode' => tomedia($result['full_path'] ) ) );
  952. die();
  953. }else{
  954. $commiss_qrcode = $member_info['commiss_qrcode'];
  955. echo json_encode( array('code' => 0, 'commiss_qrcode' => tomedia($commiss_qrcode) ) );
  956. die();
  957. }
  958. }
  959. }