User.php 21 KB

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