DistributionController.class.php 37 KB

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