Memberinviter.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Memberinviter extends BaseMember {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/memberinviter.lang.php');
  21. if(!config('ds_config.inviter_open')){
  22. $this->error(lang('inviter_not_open'));
  23. }
  24. }
  25. public function add(){
  26. //判断是否已是分销员
  27. $inviter_model=model('inviter');
  28. $inviter_info=$inviter_model->getInviterInfo('i.inviter_id='.session('member_id'));
  29. if($inviter_info && $inviter_info['inviter_state']==0){
  30. $this->error(lang('inviter_view'));
  31. }
  32. if($inviter_info && $inviter_info['inviter_state']==2){
  33. $this->error(lang('inviter_close'));
  34. }
  35. if($inviter_info && $inviter_info['inviter_state']==1){
  36. $this->redirect('home/Memberinviter/index');
  37. }
  38. //是否有分销门槛
  39. if(config('ds_config.inviter_condition')){
  40. //检查消费金额
  41. $temp=Db::name('order')->where('buyer_id='.session('member_id').' AND order_state='.ORDER_STATE_SUCCESS.' AND lock_state=0')->field('SUM(order_amount) AS order_amount,SUM(refund_amount) AS refund_amount')->find();
  42. if(!$temp || ($temp['order_amount']-$temp['refund_amount'])<config('ds_config.inviter_condition_amount')){
  43. $this->error(sprintf(lang('inviter_condition_amount'),!$temp?0:($temp['order_amount']-$temp['refund_amount']),config('ds_config.inviter_condition_amount')));
  44. }
  45. }
  46. $inviter_model->addInviter(array(
  47. 'inviter_id'=>session('member_id'),
  48. 'inviter_state'=>config('ds_config.inviter_view')?0:1,
  49. 'inviter_applytime'=>TIMESTAMP,
  50. ));
  51. if(config('ds_config.inviter_view')){
  52. $this->redirect('home/Memberinviter/add');
  53. }else{
  54. $this->redirect('home/Memberinviter/index');
  55. }
  56. }
  57. /**
  58. * 推广海报【会员推广】
  59. *
  60. * @param
  61. * @return
  62. */
  63. public function index() {
  64. $member_info = $this->member_info;
  65. View::assign('inviter_url',HOME_SITE_URL.'/Login/register.html?inviter_id=' . $member_info['member_id']);
  66. //生成微信推广二维码
  67. $inviter_model=model('inviter');
  68. $qrcode_weixin = $inviter_model->qrcode_weixin($member_info);
  69. View::assign('wx_error_msg',$qrcode_weixin['wx_error_msg']);
  70. View::assign('refer_qrcode_weixin',$qrcode_weixin['refer_qrcode_weixin']);
  71. //生成URL推广二维码
  72. $inviter_model->qrcode_logo($member_info);
  73. View::assign('refer_qrcode_logo',UPLOAD_SITE_URL. '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_poster.png');
  74. /* 设置买家当前菜单 */
  75. $this->setMemberCurMenu('inviter_poster');
  76. /* 设置买家当前栏目 */
  77. $this->setMemberCurItem('poster');
  78. return View::fetch($this->template_dir . 'index');
  79. }
  80. public function user(){
  81. /* 设置买家当前菜单 */
  82. $this->setMemberCurMenu('inviter_user');
  83. /* 设置买家当前栏目 */
  84. $this->setMemberCurItem('user');
  85. $member_model = model('member');
  86. $condition=array();
  87. $condition[]=array('inviter_id','=',$this->member_info['member_id']);
  88. if(input('param.member_name')){
  89. $condition[]=array('member_name','like','%'.input('param.member_name').'%');
  90. }
  91. $member_list=$member_model->getMemberList($condition, 'member_id,member_name,member_avatar,member_addtime,member_logintime', 10, 'member_id desc');
  92. if(is_array($member_list)){
  93. foreach($member_list as $key => $val){
  94. $member_list[$key]['member_addtime'] = $val['member_addtime'] ? date('Y-m-d H:i:s', $val['member_addtime']) : '';
  95. $member_list[$key]['member_logintime'] = $val['member_logintime'] ? date('Y-m-d H:i:s', $val['member_logintime']) : '';
  96. //该会员的2级内推荐会员
  97. $member_list[$key]['inviters']=array();
  98. }
  99. }
  100. View::assign('member_list', $member_list);
  101. View::assign('show_page', $member_model->page_info->render());
  102. return View::fetch($this->template_dir . 'user');
  103. }
  104. public function order(){
  105. /* 设置买家当前菜单 */
  106. $this->setMemberCurMenu('inviter_order');
  107. /* 设置买家当前栏目 */
  108. $this->setMemberCurItem('order');
  109. $condition=array();
  110. $condition[]=array('orderinviter_member_id','=', $this->member_info['member_id']);
  111. if(input('param.orderinviter_order_sn')){
  112. $condition[]=array('orderinviter_order_sn','like','%'.input('param.orderinviter_order_sn').'%');
  113. }
  114. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  115. $order_list=$orderinviter_list->items();
  116. foreach($order_list as $key => $val){
  117. $order_list[$key]['orderinviter_valid_text']=lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  118. }
  119. $page = $orderinviter_list->render();
  120. View::assign('show_page', $page);
  121. View::assign('orderinviter_list', $order_list);
  122. return View::fetch($this->template_dir . 'order');
  123. }
  124. /**
  125. * 用户中心右边,小导航
  126. *
  127. * @param string $menu_type 导航类型
  128. * @param string $menu_key 当前导航的menu_key
  129. * @return
  130. */
  131. public function getMemberItemList() {
  132. $menu_array = array(
  133. array(
  134. 'name' => 'poster',
  135. 'text' => lang('inviter_poster'),
  136. 'url' => (string)url('Memberinviter/index')
  137. ),
  138. array(
  139. 'name' => 'user',
  140. 'text' => lang('inviter_user'),
  141. 'url' => (string)url('Memberinviter/user')
  142. ),
  143. array(
  144. 'name' => 'order',
  145. 'text' => lang('inviter_order'),
  146. 'url' => (string)url('Memberinviter/order')
  147. ),
  148. );
  149. return $menu_array;
  150. }
  151. }