Memberinviter.php 6.8 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. * ============================================================================
  14. * 控制器
  15. */
  16. class Memberinviter extends BaseMember
  17. {
  18. public function initialize()
  19. {
  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. //判断是否已是分销员
  29. $inviter_model = model('inviter');
  30. $inviter_info = $inviter_model->getInviterInfo('i.inviter_id=' . session('member_id'));
  31. if ($inviter_info && $inviter_info['inviter_state'] == 0) {
  32. $this->error(lang('inviter_view'));
  33. }
  34. if ($inviter_info && $inviter_info['inviter_state'] == 2) {
  35. $this->error(lang('inviter_close'));
  36. }
  37. if ($inviter_info && $inviter_info['inviter_state'] == 1) {
  38. $this->redirect('home/Memberinviter/index');
  39. }
  40. //是否有分销门槛
  41. if (config('ds_config.inviter_condition')) {
  42. //检查消费金额
  43. $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();
  44. if (!$temp || ($temp['order_amount'] - $temp['refund_amount']) < config('ds_config.inviter_condition_amount')) {
  45. $this->error(sprintf(lang('inviter_condition_amount'), !$temp ? 0 : ($temp['order_amount'] - $temp['refund_amount']), config('ds_config.inviter_condition_amount')));
  46. }
  47. }
  48. $inviter_model->addInviter(array(
  49. 'inviter_id' => session('member_id'),
  50. 'inviter_state' => config('ds_config.inviter_view') ? 0 : 1,
  51. 'inviter_applytime' => TIMESTAMP,
  52. ));
  53. if (config('ds_config.inviter_view')) {
  54. $this->redirect('home/Memberinviter/add');
  55. } else {
  56. $this->redirect('home/Memberinviter/index');
  57. }
  58. }
  59. /**
  60. * 推广海报【会员推广】
  61. *
  62. * @param
  63. * @return
  64. */
  65. public function index()
  66. {
  67. $member_info = $this->member_info;
  68. View::assign('inviter_url', HOME_SITE_URL . '/Login/register.html?inviter_id=' . $member_info['member_id']);
  69. //生成微信推广二维码
  70. $inviter_model = model('inviter');
  71. $qrcode_weixin = $inviter_model->qrcode_weixin($member_info);
  72. View::assign('wx_error_msg', $qrcode_weixin['wx_error_msg']);
  73. View::assign('refer_qrcode_weixin', $qrcode_weixin['refer_qrcode_weixin']);
  74. //生成URL推广二维码
  75. $inviter_model->qrcode_logo($member_info);
  76. View::assign('refer_qrcode_logo', UPLOAD_SITE_URL . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_poster.png');
  77. /* 设置买家当前菜单 */
  78. $this->setMemberCurMenu('inviter_poster');
  79. /* 设置买家当前栏目 */
  80. $this->setMemberCurItem('poster');
  81. return View::fetch($this->template_dir . 'index');
  82. }
  83. public function user()
  84. {
  85. /* 设置买家当前菜单 */
  86. $this->setMemberCurMenu('inviter_user');
  87. /* 设置买家当前栏目 */
  88. $this->setMemberCurItem('user');
  89. $member_model = model('member');
  90. $condition = array();
  91. $condition[] = array('inviter_id', '=', $this->member_info['member_id']);
  92. if (input('param.member_name')) {
  93. $condition[] = array('member_name', 'like', '%' . input('param.member_name') . '%');
  94. }
  95. $member_list = $member_model->getMemberList($condition, 'member_id,member_name,member_avatar,member_addtime,member_logintime', 10, 'member_id desc');
  96. if (is_array($member_list)) {
  97. foreach ($member_list as $key => $val) {
  98. $member_list[$key]['member_addtime'] = $val['member_addtime'] ? date('Y-m-d H:i:s', $val['member_addtime']) : '';
  99. $member_list[$key]['member_logintime'] = $val['member_logintime'] ? date('Y-m-d H:i:s', $val['member_logintime']) : '';
  100. //该会员的2级内推荐会员
  101. $member_list[$key]['inviters'] = array();
  102. }
  103. }
  104. View::assign('member_list', $member_list);
  105. View::assign('show_page', $member_model->page_info->render());
  106. return View::fetch($this->template_dir . 'user');
  107. }
  108. public function order()
  109. {
  110. /* 设置买家当前菜单 */
  111. $this->setMemberCurMenu('inviter_order');
  112. /* 设置买家当前栏目 */
  113. $this->setMemberCurItem('order');
  114. $condition = array();
  115. $condition[] = array('orderinviter_member_id', '=', $this->member_info['member_id']);
  116. if (input('param.orderinviter_order_sn')) {
  117. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  118. }
  119. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  120. $order_list = $orderinviter_list->items();
  121. foreach ($order_list as $key => $val) {
  122. $order_list[$key]['orderinviter_valid_text'] = lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  123. }
  124. $page = $orderinviter_list->render();
  125. View::assign('show_page', $page);
  126. View::assign('orderinviter_list', $order_list);
  127. return View::fetch($this->template_dir . 'order');
  128. }
  129. /**
  130. * 用户中心右边,小导航
  131. *
  132. * @param string $menu_type 导航类型
  133. * @param string $menu_key 当前导航的menu_key
  134. * @return
  135. */
  136. public function getMemberItemList()
  137. {
  138. $menu_array = array(
  139. array(
  140. 'name' => 'poster',
  141. 'text' => lang('inviter_poster'),
  142. 'url' => (string)url('Memberinviter/index')
  143. ),
  144. array(
  145. 'name' => 'user',
  146. 'text' => lang('inviter_user'),
  147. 'url' => (string)url('Memberinviter/user')
  148. ),
  149. array(
  150. 'name' => 'order',
  151. 'text' => lang('inviter_order'),
  152. 'url' => (string)url('Memberinviter/order')
  153. ),
  154. );
  155. return $menu_array;
  156. }
  157. }