Memberinviter.php 9.6 KB

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