UserRank.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\RegionalAgency;
  4. use app\common\model\User;
  5. use app\common\model\UserPartner;
  6. use library\tools\Data;
  7. /**
  8. * @title 会员区域代理&&分销
  9. * @controller UserRank
  10. * @group base
  11. */
  12. class UserRank extends Base
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. parent::checkLogin();
  18. }
  19. /**
  20. * @title 申请(编辑)成为区域代理
  21. * @desc 申请(编辑)成为区域代理
  22. * @author qc
  23. * @url /api/User_rank/applyAgency
  24. * @method POST
  25. * @header name:Authorization require:1 desc:Token
  26. * @param name:true_name type:string default:-- desc:名称
  27. * @param name:birth type:string default:-- desc:出生日期
  28. * @param name:pro_id type:int default:-- desc:省id
  29. * @param name:city_id type:int default:-- desc:省id
  30. * @param name:pro_name type:string default:-- desc:省名
  31. * @param name:city_name type:string default:-- desc:市名
  32. * @param name:cer_type type:int default:1 desc:证件类型(1身份证)
  33. * @param name:cer_num type:string default:-- desc:证件号
  34. * @param name:detail type:srting default:-- desc:申请详情介绍
  35. */
  36. public function applyAgency()
  37. {
  38. $true_name = input('post.true_name');
  39. $birth = input('post.birth');
  40. $pro_id = input('post.pro_id');
  41. $city_id = input('post.city_id');
  42. $pro_name = input('post.pro_name');
  43. $city_name = input('post.city_name');
  44. $cer_type = input('post.cer_type');
  45. $cer_num = input('post.cer_num');
  46. $detail = input('post.detail');
  47. $is_agency = User::where('id',$this->user_id)->value('is_agency');
  48. if($is_agency) $this->error('您已经是区域代理');
  49. $check_apply = RegionalAgency::where(['pro_id'=>$pro_id,'city_id'=>$city_id])->find();
  50. if($check_apply){
  51. if($check_apply->user_id == $this->user_id && $check_apply->status == 0) $this->error('已申请,请等待审核');
  52. if($check_apply->user_id == $this->user_id && $check_apply->status == 1) $this->error('您已经是该区域代理');
  53. if($check_apply->user_id != $this->user_id && in_array( $check_apply->status ,[0,1])) $this->error('该区域已有代理');
  54. }
  55. $apply_info = [
  56. 'user_id' => $this->user_id ,
  57. 'true_name' => $true_name ,
  58. 'birth' => $birth,
  59. 'pro_id' => $pro_id ,
  60. 'city_id' => $city_id ,
  61. 'pro_name' => $pro_name ,
  62. 'city_name' => $city_name ,
  63. 'cer_type' => $cer_type ,
  64. 'cer_num' => $cer_num ,
  65. 'detail' => $detail ,
  66. 'create_at' => date('Y-m-d H:i:s') ,
  67. 'status'=> 0 ,
  68. ];
  69. Data::save('RegionalAgency',$apply_info,'user_id',['user_id'=>$this->user_id]);
  70. $this->success('申请成功,请等待审核');
  71. }
  72. /**
  73. * @title 验证区域代理
  74. * @desc 验证区域代理
  75. * @author qc
  76. * @url /api/User_rank/checkAgency
  77. * @method GET
  78. * @header name:Authorization require:1 desc:Token
  79. * @param name:pro_id type:int default:-- desc:省id
  80. * @param name:city_id type:int default:-- desc:市id
  81. * @return name:check_id type:int default:-- desc:大于0该市有申请记录
  82. */
  83. public function checkAgency()
  84. {
  85. $pro_id = input('get.pro_id');
  86. $city_id = input('get.city_id');
  87. $check_id = RegionalAgency::where(['pro_id'=>$pro_id,'city_id'=>$city_id])->where('status','<',2)->value('id');
  88. $this->success('ok',['check_id'=>intval($check_id)]);
  89. }
  90. /**
  91. * @title 获取我的区域申请记录
  92. * @desc 获取我的区域申请记录
  93. * @author qc
  94. * @url /api/User_rank/getAgencyApply
  95. * @method GET
  96. * @header name:Authorization require:1 desc:Token
  97. * @return name:true_name:int default:-- desc:名称
  98. * @return name:birth:int default:-- desc:出生日期
  99. * @return name:pro_id type:int default:-- desc:省id
  100. * @return name:city_id type:int default:-- desc:省id
  101. * @return name:pro_name type:string default:-- desc:省名
  102. * @return name:city_name type:string default:-- desc:市名
  103. * @return name:cer_type type:int default:1 desc:证件类型(1身份证)
  104. * @return name:cer_num type:string default:-- desc:证件号
  105. * @return name:detail type:srting default:-- desc:申请详情介绍
  106. * @return name:status type:int default:-- desc:审核状态(0未审核,1审核通过,2审核拒绝)
  107. * @return name:check_desc type:string default:-- desc:审核备注
  108. */
  109. public function getAgencyApply()
  110. {
  111. $detail = RegionalAgency::where(['user_id'=>$this->user_id])->find();
  112. $this->success('ok',['list'=>$detail ? $detail->toArray() :[]]);
  113. }
  114. /**
  115. * @title 申请(编辑)成为分销商
  116. * @desc 申请(编辑)成为分销商
  117. * @author qc
  118. * @url /api/User_rank/applyPartner
  119. * @method POST
  120. * @header name:Authorization require:1 desc:Token
  121. * @param name:true_name:int default:-- desc:名称
  122. * @param name:cer_num type:string default:-- desc:证件号
  123. * @param name:address type:string default:-- desc:地址
  124. * @param name:phone type:string default:-- desc:电话
  125. * @param name:detail type:srting default:-- desc:申请详情介绍
  126. */
  127. public function applyPartner()
  128. {
  129. $true_name = input('post.true_name');
  130. $cer_num = input('post.cer_num');
  131. $address = input('post.address');
  132. $detail = input('post.detail');
  133. $phone = input('post.phone');
  134. $partner_lev = User::where(['id'=>$this->user_id])->value('partner_lev');
  135. if($partner_lev) $this->error('您已经是分销商');
  136. $apply_info = [
  137. 'user_id' => $this->user_id ,
  138. 'true_name' => $true_name ,
  139. 'cer_num' => $cer_num ,
  140. 'address' => $address ,
  141. 'phone' => $phone ,
  142. 'detail' => $detail ,
  143. 'create_at' => date('Y-m-d H:i:s') ,
  144. 'status'=> 0 ,
  145. ];
  146. Data::save('UserPartner',$apply_info,'user_id',['user_id'=>$this->user_id]);
  147. $this->success('申请成功,请等待审核');
  148. }
  149. /**
  150. * @title 获取成为分销商记录申请记录
  151. * @desc 获取成为分销商记录申请记录
  152. * @author qc
  153. * @url /api/User_rank/getPartnerApply
  154. * @method GET
  155. * @header name:Authorization require:1 desc:Token
  156. * @return name:true_name:int default:-- desc:名称
  157. * @return name:cer_num type:string default:-- desc:证件号
  158. * @return name:address type:string default:-- desc:地址
  159. * @return name:phone type:string default:-- desc:电话
  160. * @return name:detail type:srting default:-- desc:申请详情介绍
  161. * @return name:status type:int default:-- desc:审核状态(0未审核,1审核通过,2审核拒绝)
  162. * @return name:check_desc type:string default:-- desc:审核备注
  163. */
  164. public function getPartnerApply()
  165. {
  166. $detail = UserPartner::where(['user_id'=>$this->user_id])->find();
  167. $this->success('ok',['list'=>$detail ? $detail->toArray() :[]]);
  168. }
  169. }