Memberinviter.php 7.1 KB

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