Apply.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\fenxiao\api\controller;
  11. use addon\fenxiao\model\Config;
  12. use addon\fenxiao\model\FenxiaoApply;
  13. use addon\fenxiao\model\Fenxiao;
  14. use app\api\controller\BaseApi;
  15. /**
  16. * 申请分销商
  17. */
  18. class Apply extends BaseApi
  19. {
  20. /**
  21. * 判断分销商名称是否存在
  22. */
  23. public function existFenxiaoName()
  24. {
  25. $token = $this->checkToken();
  26. if ($token[ 'code' ] < 0) return $this->response($token);
  27. $fenxiao_name = isset($this->params[ 'fenxiao_name' ]) ? $this->params[ 'fenxiao_name' ] : '';//分销商名称
  28. if (empty($fenxiao_name)) {
  29. return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
  30. }
  31. $apply_model = new FenxiaoApply();
  32. $res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
  33. return $this->response($res);
  34. }
  35. /**
  36. * 申请成为分销商
  37. */
  38. public function applyFenxiao()
  39. {
  40. $token = $this->checkToken();
  41. if ($token[ 'code' ] < 0) return $this->response($token);
  42. $fenxiao_name = isset($this->params[ 'fenxiao_name' ]) ? $this->params[ 'fenxiao_name' ] : '';//分销商名称
  43. $mobile = isset($this->params[ 'mobile' ]) ? $this->params[ 'mobile' ] : '';//联系电话
  44. $config = new Config();
  45. $basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
  46. if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能'));
  47. if ($basics_config[ 'is_apply' ] == 1) {
  48. if (empty($fenxiao_name)) {
  49. return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
  50. }
  51. if (empty($mobile)) {
  52. return $this->response($this->error('', 'REQUEST_MOBILE'));
  53. }
  54. $apply_model = new FenxiaoApply();
  55. $res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
  56. } else if ($basics_config[ 'is_apply' ] == 0) {
  57. $apply_model = new Fenxiao();
  58. $res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
  59. } else {
  60. return $this->response($this->error('', '未开启分销商申请'));
  61. }
  62. return $this->response($res);
  63. }
  64. public function info()
  65. {
  66. $token = $this->checkToken();
  67. if ($token[ 'code' ] < 0) return $this->response($token);
  68. $apply_model = new Fenxiao();
  69. $apply_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status');
  70. }
  71. /**
  72. * 获取申请分销商状态
  73. * @return false|string
  74. */
  75. public function status()
  76. {
  77. $token = $this->checkToken();
  78. if ($token[ 'code' ] < 0) return $this->response($token);
  79. $apply_model = new FenxiaoApply();
  80. $res = $apply_model->getFenxiaoApplyInfo([ [ 'member_id', '=', $this->member_id ] ], 'status');
  81. return $this->response($res);
  82. }
  83. }