Memberinviter.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 分销控制器
  11. */
  12. class Memberinviter extends MobileMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberinviter.lang.php');
  18. if (!config('ds_config.inviter_open')) {
  19. ds_json_encode(10001, lang('inviter_not_open'));
  20. }
  21. }
  22. /**
  23. * @api {POST} api/Memberinviter/check 检测是否有推广权限,符合条件自动新增推广员
  24. * @apiVersion 1.0.0
  25. * @apiGroup Memberinviter
  26. *
  27. * @apiHeader {String} X-DS-KEY 用户授权token
  28. *
  29. * @apiSuccess {String} code 返回码,10000为成功
  30. * @apiSuccess {String} message 返回消息
  31. */
  32. public function check()
  33. {
  34. $inviter_model = model('inviter');
  35. $inviter_info = $inviter_model->getInviterInfo('i.inviter_id=' . $this->member_info['member_id']);
  36. if (!$inviter_info) {
  37. //是否有分销门槛
  38. if (config('ds_config.inviter_condition')) {
  39. //检查消费金额
  40. $temp = Db::name('order')->where('buyer_id=' . $this->member_info['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. ds_json_encode(10001, 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' => $this->member_info['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. ds_json_encode(10001, lang('inviter_view'));
  52. } else {
  53. ds_json_encode(10000, '');
  54. }
  55. } else {
  56. if ($inviter_info['inviter_state'] == 0) {
  57. ds_json_encode(10001, lang('inviter_view'));
  58. } elseif ($inviter_info['inviter_state'] == 2) {
  59. ds_json_encode(10001, lang('inviter_close'));
  60. } else {
  61. ds_json_encode(10000, '');
  62. }
  63. }
  64. }
  65. /**
  66. * @api {POST} api/Memberinviter/index 首页显示
  67. * @apiVersion 1.0.0
  68. * @apiGroup Memberinviter
  69. *
  70. * @apiHeader {String} X-DS-KEY 用户授权token
  71. *
  72. * @apiSuccess {String} code 返回码,10000为成功
  73. * @apiSuccess {String} message 返回消息
  74. * @apiSuccess {Object} result 返回数据
  75. * @apiSuccess {String} result.refer_qrcode_logo 分销海报
  76. * @apiSuccess {String} result.inviter_url 分销url
  77. * @apiSuccess {String} result.refer_qrcode_weixin 分销微信二维码
  78. * @apiSuccess {String} result.wx_error_msg 微信错误信息
  79. */
  80. public function index()
  81. {
  82. $member_info = $this->member_info;
  83. //生成微信推广二维码
  84. $inviter_model = model('inviter');
  85. $qrcode_weixin = $inviter_model->qrcode_weixin($member_info);
  86. //生成URL推广二维码
  87. $inviter_model->qrcode_logo($member_info);
  88. $condition = array();
  89. $condition[] = array('i.inviter_id', '=', $member_info['member_id']);
  90. $inviter_member = $inviter_model->getInviterInfo($condition);
  91. $result = array(
  92. 'refer_qrcode_logo' => UPLOAD_SITE_URL . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_poster.png',
  93. 'inviter_url' => config('ds_config.h5_site_url') . '/pages/home/memberregister/Register?inviter_id=' . $member_info['member_id'],
  94. 'refer_qrcode_weixin' => $qrcode_weixin['refer_qrcode_weixin'],
  95. 'wx_error_msg' => $qrcode_weixin['wx_error_msg'],
  96. 'inviter_member' => $inviter_member
  97. );
  98. ds_json_encode(10000, '', $result);
  99. }
  100. /**
  101. * @api {POST} api/Memberinviter/user 获取推广会员
  102. * @apiVersion 1.0.0
  103. * @apiGroup Memberinviter
  104. *
  105. * @apiHeader {String} X-DS-KEY 用户授权token
  106. *
  107. * @apiParam {Int} page 页码
  108. * @apiParam {Int} per_page 每页数量
  109. *
  110. * @apiSuccess {String} code 返回码,10000为成功
  111. * @apiSuccess {String} message 返回消息
  112. * @apiSuccess {Object} result 返回数据
  113. * @apiSuccess {Object[]} result.list 用户列表
  114. * @apiSuccess {Int} result.list.member_id 用户ID
  115. * @apiSuccess {String} result.list.member_name 用户名称
  116. * @apiSuccess {String} result.list.member_avatar 用户头像
  117. * @apiSuccess {String} result.list.member_addtime 注册时间
  118. * @apiSuccess {String} result.list.member_logintime 登录时间
  119. * @apiSuccess {Object[]} result.list.inviters 上级分销员列表
  120. * @apiSuccess {Int} result.page_total 总页数
  121. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  122. */
  123. public function user()
  124. {
  125. $member_model = model('member');
  126. $condition = array(array('inviter_id', '=', $this->member_info['member_id']));
  127. if (input('param.member_name')) {
  128. $condition[] = array('member_name', 'like', '%' . input('param.member_name') . '%');
  129. }
  130. $list = $member_model->getMemberList($condition, 'member_id,member_name,member_avatar,member_addtime,member_logintime', 10, 'member_id desc');
  131. if (is_array($list)) {
  132. foreach ($list as $key => $val) {
  133. $list[$key]['member_avatar'] = get_member_avatar($val['member_avatar']) . '?' . microtime();
  134. $list[$key]['member_addtime'] = $val['member_addtime'] ? date('Y-m-d H:i:s', $val['member_addtime']) : '';
  135. $list[$key]['member_logintime'] = $val['member_logintime'] ? date('Y-m-d H:i:s', $val['member_logintime']) : '';
  136. //该会员的2级内推荐会员
  137. $list[$key]['inviters'] = array();
  138. }
  139. }
  140. $result = array_merge(array('list' => $list), mobile_page($member_model->page_info));
  141. ds_json_encode(10000, '', $result);
  142. }
  143. /**
  144. * @api {POST} api/Memberinviter/order 获取推广业绩
  145. * @apiVersion 1.0.0
  146. * @apiGroup Memberinviter
  147. *
  148. * @apiHeader {String} X-DS-KEY 用户授权token
  149. *
  150. * @apiParam {Int} page 页码
  151. * @apiParam {Int} per_page 每页数量
  152. *
  153. * @apiSuccess {String} code 返回码,10000为成功
  154. * @apiSuccess {String} message 返回消息
  155. * @apiSuccess {Object} result 返回数据
  156. * @apiSuccess {Object[]} result.list 分销业绩列表
  157. * @apiSuccess {Int} result.list.orderinviter_id 分销业绩ID
  158. * @apiSuccess {Int} result.list.orderinviter_order_id 订单ID
  159. * @apiSuccess {Int} result.list.orderinviter_member_id 用户ID
  160. * @apiSuccess {Float} result.list.orderinviter_money 分销金额
  161. * @apiSuccess {String} result.list.orderinviter_remark 分销业绩描述
  162. * @apiSuccess {String} result.list.orderinviter_member_name 用户名称
  163. * @apiSuccess {String} result.list.orderinviter_order_sn 订单编号
  164. * @apiSuccess {Int} result.list.orderinviter_goods_commonid 商品公共ID
  165. * @apiSuccess {Int} result.list.orderinviter_goods_id 商品ID
  166. * @apiSuccess {Int} result.list.orderinviter_level 分销级别
  167. * @apiSuccess {String} result.list.orderinviter_goods_name 分销商品名称
  168. * @apiSuccess {Int} result.list.orderinviter_valid 是否有效 0否1是
  169. * @apiSuccess {Int} result.list.orderinviter_store_id 店铺ID
  170. * @apiSuccess {Int} result.list.orderinviter_order_type 订单类型(0实物订单1虚拟订单)
  171. * @apiSuccess {Int} result.list.orderinviter_goods_quantity 购买数量
  172. * @apiSuccess {Float} result.list.orderinviter_goods_amount 商品总价
  173. * @apiSuccess {String} result.list.orderinviter_store_name 店铺名称
  174. * @apiSuccess {Int} result.list.orderinviter_addtime 添加时间
  175. * @apiSuccess {Int} result.page_total 总页数
  176. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  177. */
  178. public function order()
  179. {
  180. $condition = array(array('orderinviter_member_id', '=', $this->member_info['member_id']));
  181. if (input('param.orderinviter_order_sn')) {
  182. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  183. }
  184. $list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(['list_rows' => 10, 'query' => request()->param()], false);
  185. $order_list = $list->items();
  186. foreach ($order_list as $key => $val) {
  187. $order_list[$key]['orderinviter_valid_text'] = lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  188. }
  189. $result = array_merge(array('list' => $order_list), mobile_page($list));
  190. ds_json_encode(10000, '', $result);
  191. }
  192. }