UserManage.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\DeliveryAddress;
  4. use app\common\model\UserLevel;
  5. use think\Db;
  6. use app\common\model\User;
  7. use app\common\model\InviteInfo;
  8. /**
  9. * @title 会员管理
  10. * @controller UserManage
  11. * @group base
  12. */
  13. class UserManage extends Base
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. parent::checkLogin();
  19. }
  20. /**
  21. * @title 设置收货地址(新增或修改)
  22. * @desc 设置收货地址(新增或修改)
  23. * @author qc
  24. * @url /api/User_manage/setDeliveryAddress
  25. * @method POST
  26. * @header name:Authorization require:1 desc:Token
  27. * @param name:id type:int : default:0 desc:收货地址记录id(不传值是添加)
  28. * @param name:pro_name type:int require:1 default:-- desc:省名
  29. * @param name:city_name type:int require:1 default:-- desc:市名
  30. * @param name:county_name type:int require:1 default:-- desc:县区名
  31. * @param name:street_name type:int require:1 default:-- desc:街道
  32. * @param name:detail type:string require:1 default:-- desc:详细地址
  33. * @param name:phone type:string require:1 default:-- desc:联系电话
  34. * @param name:name type:string require:1 default:-- desc:联系人
  35. * @param name:is_mr type:int require:0 default:0 desc:是否是默认(0不默认,1默认)
  36. */
  37. public function setDeliveryAddress()
  38. {
  39. $pro_name = input('post.pro_name');// 省
  40. $city_name = input('post.city_name');// 市
  41. $county_name = input('post.county_name');// 县区
  42. $street_name = input('post.street_name');// 县区
  43. $pro_id = Db::name('store_area')->where('name',$pro_name)->value('id');
  44. $city_id = Db::name('store_area')->where('name',$city_name)->value('id');
  45. $county_id = Db::name('store_area')->where('name',$county_name)->value('id');
  46. $detail = input('post.detail');// 详细地址
  47. $phone = input('post.phone');
  48. $name = input('post.name');
  49. $id = input('post.id');
  50. $is_mr = input('post.is_mr',0);
  51. $set_data = compact(['pro_id','city_id','county_id','detail','phone','name','is_mr']);
  52. $set_data['user_id'] = $this->user_id;
  53. $set_data['pro_name'] = $pro_name;
  54. $set_data['city_name'] = $city_name;
  55. $set_data['county_name']= $county_name;
  56. $set_data['street_name']= $street_name;
  57. $set_data['mer_name']=$pro_name . $city_name. $county_name;
  58. if($id) {
  59. Db::name('delivery_address')->where(['id'=>$id])->update($set_data);
  60. }else{
  61. Db::name('delivery_address')->insert($set_data);
  62. $id = Db::getLastInsID();
  63. }
  64. if($is_mr) Db::name('delivery_address')->where('user_id','=',$this->user_id)->where('id','<>',$id)->where('is_mr','=',1)->update(['is_mr'=>0]);
  65. $this->success('编辑成功');
  66. }
  67. /**
  68. * @title 修改默认收货地址
  69. * @desc 修改默认收货地址
  70. * @author qc
  71. * @url /api/User_manage/changeApproveDelivery
  72. * @method POST
  73. * @header name:Authorization require:1 desc:Token
  74. * @param name:id type:int default:0 desc:收货地址记录id
  75. * @param name:is_mr type:int default:1 desc:是否是默认(0不默认,1默认)
  76. */
  77. public function changeApproveDelivery()
  78. {
  79. $id = input('post.id');
  80. $is_mr = input('post.is_mr',1);
  81. if($is_mr) {
  82. Db::name('delivery_address')
  83. ->where('user_id','=',$this->user_id)
  84. ->where('is_mr','=',1)
  85. ->update(['is_mr'=>0]);
  86. Db::name('delivery_address')
  87. ->where('user_id','=',$this->user_id)
  88. ->where('id','=',$id)
  89. ->update(['is_mr'=>1]);
  90. }else{
  91. Db::name('delivery_address')
  92. ->where('user_id','=',$this->user_id)
  93. ->where('id','=',$id)
  94. ->update(['is_mr'=>0]);
  95. }
  96. $this->success('修改成功');
  97. }
  98. /**
  99. * @title 删除收货地址
  100. * @desc 删除收货地址
  101. * @author qc
  102. * @url /api/User_manage/delDeliveryAddress
  103. * @method POST
  104. * @header name:Authorization require:1 desc:Token
  105. * @param name:id type:int require:1 default:1 desc:收货地址记录id
  106. */
  107. public function delDeliveryAddress()
  108. {
  109. $id = input('post.id');
  110. if(!$id)$this->error('请选择要删除的收货地址');
  111. Db::name('delivery_address')->where(['user_id'=>$this->user_id,'id'=>$id])->update(['is_deleted'=>1,'is_mr'=>0]);
  112. $this->success('删除成功!');
  113. }
  114. /**
  115. * @title 获取收货地址列表
  116. * @desc 获取收货地址列表
  117. * @author qc
  118. * @url /api/User_manage/getDeliveryAddressList
  119. * @method GET
  120. * @header name:Authorization require:1 desc:Token
  121. * @param name:page type:int default:1 desc:页数
  122. * @param name:page_num type:int default:20 desc:每页数
  123. * @return name:pro_id type:int default:-- desc:省id
  124. * @return name:city_id type:int default:-- desc:市id
  125. * @return name:county_id type:int default:-- desc:县区id
  126. * @return name:pro_name type:string default:-- desc:省名
  127. * @return name:city_name type:string default:-- desc:市名
  128. * @return name:county_name type:string default:-- desc:县区名
  129. * @return name:street_name type:string default:-- desc:街道名称
  130. * @return name:detail type:string default:-- desc:详细地址
  131. * @return name:phone type:string default:-- desc:联系电话
  132. * @return name:name type:string default:-- desc:联系人
  133. * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
  134. */
  135. public function getDeliveryAddressList()
  136. {
  137. $list = DeliveryAddress::where(['user_id'=>$this->user_id,'is_deleted'=>0])
  138. ->order('is_mr desc ,id desc')
  139. ->limit($this->off_set,$this->page_num)
  140. ->select()->toArray();
  141. $this->success('ok',['list'=>$list]);
  142. }
  143. /**
  144. * @title 获取收货地址详情
  145. * @desc 获取收货地址详情
  146. * @author qc
  147. * @url /api/User_manage/getDeliveryAddressDetail
  148. * @method GET
  149. * @header name:Authorization require:1 desc:Token
  150. * @param name:id type:int default:1 desc:收货地址记录id
  151. * @return name:pro_id type:int default:-- desc:省id
  152. * @return name:city_id type:int default:-- desc:市id
  153. * @return name:county_id type:int default:-- desc:县区id
  154. * @return name:pro_name type:string default:-- desc:省名
  155. * @return name:city_name type:string default:-- desc:市名
  156. * @return name:county_name type:string default:-- desc:县区名
  157. * @return name:street_name type:string default:-- desc:街道名
  158. * @return name:detail type:string default:-- desc:详细地址
  159. * @return name:phone type:string default:-- desc:联系电话
  160. * @return name:name type:string default:-- desc:联系人
  161. * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
  162. */
  163. public function getDeliveryAddressDetail()
  164. {
  165. $detail = Db::name('delivery_address')->find(input('id'));
  166. $this->success('ok',$detail);
  167. }
  168. /**
  169. * @title 获取默认收货地址详情
  170. * @desc 获取默认收货地址详情
  171. * @author qc
  172. * @url /api/User_manage/getDefaultAddress
  173. * @method GET
  174. * @header name:Authorization require:1 desc:Token
  175. * @return name:pro_id type:int default:-- desc:省id
  176. * @return name:city_id type:int default:-- desc:市id
  177. * @return name:county_id type:int default:-- desc:县区id
  178. * @return name:pro_name type:string default:-- desc:省名
  179. * @return name:city_name type:string default:-- desc:市名
  180. * @return name:county_name type:string default:-- desc:县区名
  181. * @return name:street_name type:string default:-- desc:街道名
  182. * @return name:detail type:string default:-- desc:详细地址
  183. * @return name:phone type:string default:-- desc:联系电话
  184. * @return name:name type:string default:-- desc:联系人
  185. * @return name:is_mr type:int default:0 desc:是否是默认(0不默认,1默认)
  186. */
  187. public function getDefaultAddress()
  188. {
  189. $default = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
  190. $detail = $default ? $default->toArray() : '';
  191. $this->success('ok',$detail);
  192. }
  193. /**
  194. * @title 绑定推荐人
  195. * @desc 绑定推荐人
  196. * @author qc
  197. * @url /api/User_manage/bindParent
  198. * @method POST
  199. * @header name:Authorization require:1 desc:Token
  200. * @param name:invite_code type:string default:-- desc:推荐码
  201. */
  202. public function bindParent()
  203. {
  204. $invite_code = input('post.invite_code','');
  205. $user_info = $this->userInfo();
  206. if($user_info['pid']) $this->error('已绑定推荐人');
  207. $invite_info = User::where(['invite_code'=>$invite_code])->find();
  208. if(!$invite_info) $this->error('推荐码错误');
  209. if(!$invite_info->id > $this->user_id) $this->error('无法绑定改会员为推荐人!');
  210. User::update(['pid'=>$invite_info->id],['id'=>$this->user_id]);
  211. InviteInfo::create(['user_id'=>$this->user_id,'pid'=>$invite_info->id,'create_at'=>date('Y-m-d H:i:s'),'type'=>2]);
  212. $this->success('用户绑定成功');
  213. }
  214. /**
  215. * @title 获取推荐人信息
  216. * @desc 获取推荐人信息
  217. * @author qc
  218. * @url /api/User_manage/getParentInfo
  219. * @method GET
  220. * @header name:Authorization require:1 desc:Token
  221. * @return name:name type:string default:-- desc:昵称
  222. * @return name:headimg type:string default:-- desc:头像
  223. * @return name:create_at type:string default:-- desc:注册时间
  224. */
  225. public function getParentInfo()
  226. {
  227. $pid = User::where('id',$this->user_id)->value('pid');
  228. $parent_info = [];
  229. if($pid) $parent_info= User::field('id,name,headimg,create_at')->where('id',$this->user_id)->find()->toArray();
  230. $this->success('ok',$parent_info);
  231. }
  232. /**
  233. * @title 通过邀请码获取用户信息(绑定推荐人可用)
  234. * @desc 通过邀请码获取用户信息(绑定推荐人可用)
  235. * @author qc
  236. * @url /api/User_manage/getParentInfo
  237. * @method GET
  238. * @header name:Authorization require:1 desc:Token
  239. * @param name:invite_code type:string default:-- desc:邀请码
  240. * @return name:name type:string default:-- desc:名称
  241. * @return name:headimg type:string default:-- desc:头像
  242. * @return name:create_at type:string default:-- desc:注册时间
  243. */
  244. public function getUserInfoByCode()
  245. {
  246. $invite_code = input('get.invite_code');
  247. $detail = User::field('id,name,headimg')->where(['invite_code'=>$invite_code])->find();
  248. if(!$detail) $this->error('没有找到用户');
  249. $this->success('ok',['detail'=>$detail->toArray()]);
  250. }
  251. /**
  252. * @title 获取我邀请的会员列表(我的粉丝)
  253. * @desc 获取我邀请的会员列表
  254. * @author qc
  255. * @url /api/User_manage/getMyInviteList
  256. * @method GET
  257. * @header name:Authorization require:1 desc:Token
  258. * @param name:page type:int default:1 desc:页数
  259. * @param name:page_num type:int default:20 desc:每页数
  260. * @return name:name type:string default:-- desc:昵称
  261. * @return name:headimg type:string default:-- desc:头像
  262. * @return name:create_at type:string default:-- desc:注册时间
  263. */
  264. public function getMyInviteList()
  265. {
  266. $list =User::field('id,name,headimg,create_at')->where(['pid'=>$this->user_id])
  267. ->order('id desc')
  268. ->limit($this->page,$this->page_num)
  269. ->select();
  270. $this->success('ok',['list'=>$list ? $list->toArray():[]]);
  271. }
  272. /**
  273. * @title 用户反馈
  274. * @desc 用户反馈
  275. * @author qc
  276. * @url /api/User_manage/leaveFeedback
  277. * @method POST
  278. * @header name:Authorization require:1 desc:Token
  279. * @param name:phone type:string require:1 default:-- desc:电话
  280. * @param name:content type:string require:1 default:-- desc:反馈内容
  281. * @param name:images type:string require:0 default:-- desc:反馈图片(逗号隔开,没有不传)
  282. */
  283. public function leaveFeedback()
  284. {
  285. $insert_data = [
  286. 'user_id'=>$this->user_id,
  287. 'content'=>input('content'),
  288. 'phone'=>input('phone'),
  289. 'images'=>input('images'),
  290. 'create_at'=>date('Y-m-d H:i:s')
  291. ];
  292. Db::name('user_feedback')->insert($insert_data);
  293. $this->success('反馈成功',Db::getLastInsID());
  294. }
  295. /**
  296. * @title 获取会员等级设置
  297. * @desc 获取我邀请的会员列表
  298. * @author qc
  299. * @url /api/User_manage/getUserLevelSet
  300. * @method GET
  301. * @header name:Authorization require:1 desc:Token
  302. * @return name:id type:int default:-- desc:等级id
  303. * @return name:name type:string default:-- desc:名称
  304. * @return name:desc type:string default:-- desc:描述
  305. * @return name:growth type:string default:-- desc:积分数
  306. */
  307. public function getUserLevelSet()
  308. {
  309. $list = UserLevel::field('id,name,desc,growth')->select()->toArray();
  310. $this->success('ok',['list'=>$list]);
  311. }
  312. }