User.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php
  2. namespace app\data\controller\api\business;
  3. use app\data\controller\api\Auth;
  4. use app\data\model\DataMerchants;
  5. use app\data\model\ShopFeedback;
  6. use app\data\model\SystemUserAddress;
  7. use app\data\model\SystemUserAmount;
  8. use app\data\model\SystemUserBank;
  9. use app\data\model\SystemUserWithdrawal;
  10. use think\admin\Controller;
  11. use hg\apidoc\annotation\Title;
  12. use hg\apidoc\annotation\Method;
  13. use hg\apidoc\annotation\Param;
  14. use hg\apidoc\annotation\Returned;
  15. use think\admin\model\SystemUser;
  16. use think\Request;
  17. /**
  18. * 商家个人中心
  19. */
  20. class User extends Auth
  21. {
  22. /**
  23. * 控制器初始化
  24. */
  25. protected function initialize()
  26. {
  27. $purchase_model = new Common($this->app);
  28. $user = $purchase_model->uuid();
  29. $this->user = $user;
  30. }
  31. /**
  32. * @Title ("用户信息")
  33. * @Method ("get")
  34. * @Returned("merchant.head_img",desc="商家头像")
  35. * @Returned("merchant.name",desc="商家名称")
  36. * @Returned("merchant.full_address",desc="详细地址")
  37. * @Returned("merchant.contact_name",desc="联系人")
  38. * @Returned("merchant.contact_phone",desc="联系电话")
  39. * @Returned("merchant.intro",desc="商家简介")
  40. * @Returned("merchant.imgs_videos",desc="图片及视频")
  41. * @Returned("merchant.business_img",desc="营业执照")
  42. * @Returned("merchant.longitude",desc="经度")
  43. * @Returned("merchant.latitude",desc="纬度")
  44. */
  45. public function user_info(){
  46. $user_info = $this->user;
  47. $user_info['merchant']=DataMerchants::getByAdmin($user_info['id']);
  48. $this->success('用户信息',$user_info);
  49. }
  50. /**
  51. * @Title ("意见反馈")
  52. * @Method ("post")
  53. * @Param ("title",desc="反馈标题")
  54. * @Param ("content",desc="反馈内容")
  55. * @Param ("image",desc="图片")
  56. * @Param ("phone",desc="联系方式")
  57. * @return void
  58. */
  59. public function feedback(){
  60. $data = $this->_vali([
  61. 'title.require'=>'反馈标题不能为空',
  62. 'content.require'=>'反馈内容不能为空',
  63. 'image.default'=>'',
  64. 'phone.require'=>'联系方式不能为空'
  65. ]);
  66. $feedback_data= [
  67. 'admin_id'=>$this->user->id,
  68. 'title'=>$data['title'],
  69. 'content'=>$data['content'],
  70. 'image'=>$data['image'],
  71. 'phone'=>$data['phone'],
  72. 'status'=>1,
  73. 'create_time'=>date('Y-m-d H:i:s')
  74. ];
  75. ShopFeedback::mk()->insert($feedback_data);
  76. $this->success('意见反馈已提交');
  77. }
  78. /**
  79. * @Title ("反馈意见列表")
  80. * @Method ("get")
  81. * @return void
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. */
  86. public function feedback_list(){
  87. $admin_id = $this->user->id;
  88. $list = ShopFeedback::mk()->where('admin_id',$admin_id)->select();
  89. $this->success('反馈意见列表',$list);
  90. }
  91. /**
  92. * @Title ("删除意见")
  93. * @Method ("post")
  94. * @Param ("feedback_id",desc="删除意见数据id")
  95. * @return void
  96. */
  97. public function del_feedback(){
  98. $data = $this->_vali(
  99. [
  100. 'feedback_id.require'=>"参数不能为空",
  101. ]
  102. );
  103. $admin_id =$this->user->id;
  104. ShopFeedback::mk()->where('id',$data['feedback_id'])->where('admin_id',$admin_id)->delete();
  105. $this->success('反馈记录已删除');
  106. }
  107. /**
  108. * @Title ("编辑意见信息")
  109. * @Method ("post")
  110. * @Param ("feedback_id",desc="编辑意见数据id")
  111. * @Param ("title",desc="反馈标题")
  112. * @Param ("content",desc="反馈内容")
  113. * @Param ("image",desc="图片")
  114. * @Param ("phone",desc="联系方式")
  115. * @return void
  116. */
  117. public function save_feedback(){
  118. $data = $this->_vali(
  119. [
  120. 'feedback_id.require'=>"参数不能为空",
  121. 'title.require'=>'反馈标题不能为空',
  122. 'content.require'=>'反馈内容不能为空',
  123. 'image.default'=>'',
  124. 'phone.require'=>'联系方式不能为空'
  125. ]
  126. );
  127. $feedback_data=[
  128. 'title'=>$data['title'],
  129. 'content'=>$data['content'],
  130. 'image'=>$data['image'],
  131. 'phone'=>$data['phone'],
  132. 'status'=>1,
  133. 'create_time'=>date('Y-m-d H:i:s')
  134. ];
  135. $admin_id =$this->user->id;
  136. ShopFeedback::mk()->where('id',$data['feedback_id'])->where('admin_id',$admin_id)->save($feedback_data);
  137. $this->success('反馈记录已删除');
  138. }
  139. /**
  140. * @Title ("添加用户银行卡")
  141. * @Method("post")
  142. * @Param ("bank",desc="银行名称")
  143. * @Param ("number",desc="银行卡号")
  144. * @Param ("address",desc="开户行")
  145. * @Param ("real_name",desc="持卡人真是姓名")
  146. * @return void
  147. */
  148. public function bank_add(){
  149. $admin_id = $this->user->id;
  150. $data = $this->_vali([
  151. 'bank.require'=>'银行名称不能空',
  152. 'number.require'=>'银行卡号不能为空',
  153. 'address.require'=>'开户行信息不能为空',
  154. 'real_name.require'=>'持卡人姓名不能为空'
  155. ]);
  156. $bank_data = [
  157. 'admin_id'=>$admin_id,
  158. 'bank'=>$data['bank'],
  159. 'number'=>$data['number'],
  160. 'address'=>$data['address'],
  161. 'real_name'=>$data['real_name']
  162. ];
  163. SystemUserBank::mk()->insertGetId($bank_data);
  164. $this->success('银行卡添加成功');
  165. }
  166. /**
  167. * @Title ("我的银行卡列表")
  168. * @Method ("get")
  169. * @return void
  170. * @throws \think\db\exception\DataNotFoundException
  171. * @throws \think\db\exception\DbException
  172. * @throws \think\db\exception\ModelNotFoundException
  173. */
  174. public function user_bank(){
  175. $admin_id = $this->user->id;
  176. $query = SystemUserBank::mQuery();
  177. $list = $query->where('admin_id',$admin_id)->order('id desc')->page(true, false, false, 10);
  178. $this->success('银行卡列表',$list);
  179. }
  180. /**
  181. * @Title ("银行卡解绑")
  182. * @Method ("post")
  183. * @Param ("bank_id",desc="银行卡id")
  184. * @return void
  185. * @throws \think\db\exception\DataNotFoundException
  186. * @throws \think\db\exception\DbException
  187. * @throws \think\db\exception\ModelNotFoundException
  188. */
  189. public function bank_del(){
  190. $admin_id = $this->user->id;
  191. $data = $this->_vali(
  192. ['bank_id.require'=>'请选择解绑银行']
  193. );
  194. $is_have = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data['bank_id']])->find();
  195. if(empty($is_have)){
  196. $this->error('解绑信息错误');
  197. }
  198. SystemUserBank::mk()->where(['admin_id'=>$admin_id,'id'=>$data['bank_id']])->delete();
  199. $this->success('银行卡已解绑');
  200. }
  201. /**
  202. * @Title ("修改用户信息")
  203. * @Method ("post")
  204. * @Param ("headimg",desc="用户头像")
  205. * @Param ("nickname",desc="用户昵称")
  206. * @Param ("sex",desc="性别")
  207. * @return void
  208. */
  209. public function user_edit(){
  210. $admin_id= $this->user->id;
  211. $data = input();
  212. $user_data = [];
  213. if(isset($data['headimg'])){
  214. $user_data['headimg']=$data['headimg'];
  215. }
  216. if(isset($data['nickname'])){
  217. $user_data['nickname']=$data['nickname'];
  218. }
  219. if(isset($data['sex'])){
  220. $user_data['sex']=$data['sex'];
  221. }
  222. SystemUser::mk()->where('id',$admin_id)->save($user_data);
  223. $this->success('个人信息修改完成!');
  224. }
  225. /**
  226. * @Title ("邮箱绑定")
  227. * @Method ("post")
  228. * @Param ("mailbox",desc="邮箱")
  229. * @return void
  230. */
  231. public function user_mailbox(){
  232. $admin_id = $this->user->id;
  233. $data = $this->_vali(
  234. ['mailbox.require'=>'邮箱不能为空!']
  235. );
  236. SystemUser::mk()->where('id',$admin_id)->save(['contact_mail'=>$data['mailbox']]);
  237. $this->success('邮箱绑定成功');
  238. }
  239. /**
  240. * @Title ("修改密码")
  241. * @Method ("post")
  242. * @Param ("old_password",desc="原始密码")
  243. * @Param ("new_password",desc="新密码")
  244. * @return void
  245. */
  246. public function user_password(){
  247. $admin_id= $this->user->id;
  248. $data = $this->_vali(
  249. [
  250. 'old_password.require'=>'原始密码不能为空',
  251. 'new_password.require'=>'新密码不能为空'
  252. ]
  253. );
  254. if($this->user->password!=md5($data['old_password'])){
  255. $this->error('原始密码不正确');
  256. }
  257. $token=rand('00000','99999');
  258. SystemUser::mk()->where('id',$admin_id)->save(['password'=>md5($data['new_password']),'token'=>$token]);
  259. $this->success('密码重置成功请重新登录!');
  260. }
  261. /**
  262. * @Title ("商家提现申请")
  263. * @Method ("post")
  264. * @Param ("bank_number",desc="提现卡号")
  265. * @Param ("money",desc="提现金额")
  266. * @return void
  267. * @throws \think\db\exception\DataNotFoundException
  268. * @throws \think\db\exception\DbException
  269. * @throws \think\db\exception\ModelNotFoundException
  270. */
  271. public function user_withdrawal(){
  272. $admin_id= $this->user->id;
  273. $data = $this->_vali(
  274. [
  275. 'bank_number.require'=>'提现卡号不能为空',
  276. 'money.require'=>'提现金额不能为空'
  277. ]
  278. );
  279. if($data['money']<1){
  280. $this->error('提现金额不能小于'.'1');
  281. }
  282. if($data['money']>$this->user->money){
  283. $this->error('余额不足');
  284. }
  285. $bank_info = SystemUserBank::mk()->where(['admin_id'=>$admin_id,'number'=>$data['bank_number']])->find();
  286. if(!$bank_info){
  287. $this->error('提现账号有问题');
  288. }
  289. $withdrawal_data = [
  290. 'admin_id'=>$admin_id,
  291. 'real_name'=>$data['real_name'],
  292. 'bank'=>$bank_info['bank'],
  293. 'number'=>$bank_info['number'],
  294. 'address'=>$bank_info['address'],
  295. 'money'=>$data['money'],
  296. 'before'=>$this->user->money,
  297. 'after'=>$this->user->money-$data['money'],
  298. 'charges'=>10,
  299. 'amount'=>$data['money']-10,
  300. 'create_time'=>date('Y-m-d H:i:s'),
  301. 'status'=>1
  302. ];
  303. SystemUserWithdrawal::mk()->insertGetId($withdrawal_data);
  304. $this->success('提现申请已提交,等待打款');
  305. }
  306. /**
  307. * @Title ("余额记录")
  308. * @Method ("get")
  309. * @return void
  310. */
  311. public function user_amount(){
  312. $admin_id = $this->user->id;
  313. $query = SystemUserAmount::mQuery();
  314. $list = $query->where('admin_id',$admin_id)->order('id desc')->page(true, false, false, 10);
  315. $list['money'] = $this->user->money;
  316. $list['bank_nunm']=SystemUserBank::mk()->where('admin_id',$admin_id)->count();
  317. $this->success('余额记录明细',$list);
  318. }
  319. /**
  320. * @Title ("添加发货地址")
  321. * @Method ("post")
  322. * @Param ("name",desc="名称")
  323. * @Param ("phone",desc="联系方式")
  324. * @Param ("province",desc="省名称")
  325. * @Param ("city",desc="市名称")
  326. * @Param ("area",desc="区县名称")
  327. * @Param ("address",desc="详细地址")
  328. * @return void
  329. */
  330. public function add_address(){
  331. $admin_id = $this->user->id;
  332. $data = $this->_vali(
  333. [
  334. 'name.require'=>'名称不能为空',
  335. 'phone.require'=>'联系方式不能为空',
  336. 'province.require'=>'省名称不能为空',
  337. 'city.require'=>'城市名称不能为空',
  338. 'area.require'=>'区县名称不能为空',
  339. 'address.require'=>'详细地址不能为空'
  340. ]
  341. );
  342. $address_data = [
  343. 'admin_id'=>$admin_id,
  344. 'name'=>$data['name'],
  345. 'phone'=>$data['phone'],
  346. 'province'=>$data['province'],
  347. 'city'=>$data['city'],
  348. 'area'=>$data['area'],
  349. 'address'=>$data['address'],
  350. ];
  351. SystemUserAddress::mk()->insertGetId($address_data);
  352. $this->success('发货地址添加成功');
  353. }
  354. /**
  355. * @Title ("发货地址列表")
  356. * @Method ("get")
  357. * @return void
  358. */
  359. public function address_list()
  360. {
  361. $admin_id = $this->user->id;
  362. $query = SystemUserAddress::mQuery();
  363. $list = $query->where('admin_id', $admin_id)
  364. ->order('id desc')->page(true, false, false, 10);
  365. $this->success('发货地址列表', $list);
  366. }
  367. /**
  368. * @Title ("编辑发货地址")
  369. * @Method ("post")
  370. * @Param ("address_id",desc="地址id")
  371. * @Param ("name",desc="名称")
  372. * @Param ("phone",desc="联系方式")
  373. * @Param ("province",desc="省名称")
  374. * @Param ("city",desc="市名称")
  375. * @Param ("area",desc="区县名称")
  376. * @Param ("address",desc="详细地址")
  377. * @return void
  378. */
  379. public function address_edit(){
  380. $admin_id = $this->user->id;
  381. $data = $this->_vali(
  382. [
  383. 'address_id.require'=>'发货地址id',
  384. 'name.require'=>'名称不能为空',
  385. 'phone.require'=>'联系方式不能为空',
  386. 'province.require'=>'省名称不能为空',
  387. 'city.require'=>'城市名称不能为空',
  388. 'area.require'=>'区县名称不能为空',
  389. 'address.require'=>'详细地址不能为空'
  390. ]
  391. );
  392. $address_data = [
  393. 'admin_id'=>$admin_id,
  394. 'name'=>$data['name'],
  395. 'phone'=>$data['phone'],
  396. 'province'=>$data['province'],
  397. 'city'=>$data['city'],
  398. 'area'=>$data['area'],
  399. 'address'=>$data['address'],
  400. ];
  401. SystemUserAddress::mk()->where('id',$data['address_id'])->save($address_data);
  402. $this->success('发货地址编辑成功');
  403. }
  404. /**
  405. * @Title ("删除发货地址")
  406. * @Method ("post")
  407. * @Param ("address_id",desc="地址id")
  408. * @return void
  409. */
  410. public function address_del(){
  411. $admin_id = $this->user->id;
  412. $data = $this->_vali(
  413. [
  414. 'address_id.require'=>'发货地址id',
  415. ]
  416. );
  417. SystemUserAddress::mk()->where('id',$data['address_id'])->delete();
  418. $this->success('删除成功');
  419. }
  420. /**
  421. * @Title("编辑商家信息")
  422. * @Method("post")
  423. * @Param("head_img",desc="头像")
  424. * @Param("contact_name",desc="联系人")
  425. * @Param("contact_phone",desc="联系电话")
  426. * @Param("intro",desc="商家简介")
  427. * @Param("imgs_videos",desc="图片及视频,英文逗号隔开")
  428. */
  429. public function edit(Request $request){
  430. $data=$this->_vali([
  431. 'contact_name.require'=>'请填写必填项',
  432. 'contact_name.max:30'=>'联系人过长',
  433. 'contact_phone.require'=>'请填写必填项',
  434. 'contact_phone.mobile'=>'联系电话有误',
  435. 'intro.require'=>'请填写必填项',
  436. 'intro.max:500'=>'简介最多500字符',
  437. 'imgs_videos.require'=>'请填写必填项',
  438. 'head_img.url'=>'头像必须是链接',
  439. ]);
  440. if(empty($data['head_img'])){
  441. unset($data['head_img']);
  442. }
  443. $merchant=DataMerchants::getByAdmin($this->user['id']);
  444. $merchant->save($data);
  445. $this->success('更新成功');
  446. }
  447. }