User.php 19 KB

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