Memberinviter.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. *
  11. * 控制器
  12. */
  13. class Memberinviter extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinviter.lang.php');
  19. if (!config('ds_config.inviter_open')) {
  20. $this->error(lang('inviter_not_open'));
  21. }
  22. }
  23. public function add()
  24. {
  25. //判断是否已是分销员
  26. $inviter_model = model('inviter');
  27. $inviter_info = $inviter_model->getInviterInfo('i.inviter_id=' . session('member_id'));
  28. if ($inviter_info && $inviter_info['inviter_state'] == 0) {
  29. $this->error(lang('inviter_view'));
  30. }
  31. if ($inviter_info && $inviter_info['inviter_state'] == 2) {
  32. $this->error(lang('inviter_close'));
  33. }
  34. if ($inviter_info && $inviter_info['inviter_state'] == 1) {
  35. $this->redirect('home/Memberinviter/index');
  36. }
  37. //是否有分销门槛
  38. if (config('ds_config.inviter_condition')) {
  39. //检查消费金额
  40. $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();
  41. if (!$temp || ($temp['order_amount'] - $temp['refund_amount']) < config('ds_config.inviter_condition_amount')) {
  42. $this->error(sprintf(lang('inviter_condition_amount'), !$temp ? 0 : ($temp['order_amount'] - $temp['refund_amount']), config('ds_config.inviter_condition_amount')));
  43. }
  44. }
  45. $inviter_model->addInviter(array(
  46. 'inviter_id' => session('member_id'),
  47. 'inviter_state' => config('ds_config.inviter_view') ? 0 : 1,
  48. 'inviter_applytime' => TIMESTAMP,
  49. ));
  50. if (config('ds_config.inviter_view')) {
  51. $this->redirect('home/Memberinviter/add');
  52. } else {
  53. $this->redirect('home/Memberinviter/index');
  54. }
  55. }
  56. /**
  57. * 推广海报【会员推广】
  58. *
  59. * @param
  60. * @return
  61. */
  62. public function index()
  63. {
  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. /* 设置买家当前菜单 */
  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. /* 设置买家当前菜单 */
  108. $this->setMemberCurMenu('inviter_order');
  109. /* 设置买家当前栏目 */
  110. $this->setMemberCurItem('order');
  111. $condition = array();
  112. $condition[] = array('orderinviter_member_id', '=', $this->member_info['member_id']);
  113. if (input('param.orderinviter_order_sn')) {
  114. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  115. }
  116. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  117. $order_list = $orderinviter_list->items();
  118. foreach ($order_list as $key => $val) {
  119. $order_list[$key]['orderinviter_valid_text'] = lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  120. }
  121. $page = $orderinviter_list->render();
  122. View::assign('show_page', $page);
  123. View::assign('orderinviter_list', $order_list);
  124. return View::fetch($this->template_dir . 'order');
  125. }
  126. /**
  127. * 用户中心右边,小导航
  128. *
  129. * @param string $menu_type 导航类型
  130. * @param string $menu_key 当前导航的menu_key
  131. * @return
  132. */
  133. public function getMemberItemList()
  134. {
  135. $menu_array = array(
  136. array(
  137. 'name' => 'poster',
  138. 'text' => lang('inviter_poster'),
  139. 'url' => (string)url('Memberinviter/index')
  140. ),
  141. array(
  142. 'name' => 'user',
  143. 'text' => lang('inviter_user'),
  144. 'url' => (string)url('Memberinviter/user')
  145. ),
  146. array(
  147. 'name' => 'order',
  148. 'text' => lang('inviter_order'),
  149. 'url' => (string)url('Memberinviter/order')
  150. ),
  151. );
  152. return $menu_array;
  153. }
  154. }