User.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\service\passport\MailCaptcha as MailCaptchaService;
  4. use app\index\model\OrderAddress;
  5. use app\index\model\user\PointsLog as PointsLogModel;
  6. use app\index\model\Goods as GoodsModel;
  7. use app\index\model\Order as OrderModel;
  8. use think\facade\Session;
  9. /**
  10. * 默认控制器
  11. * Class User
  12. * @package app\api\controller
  13. */
  14. class User extends Controller
  15. {
  16. /**
  17. * 个人中心
  18. * @return \think\response\View
  19. */
  20. public function personal()
  21. {
  22. $userId = Session::get('user_id');
  23. if (empty($userId)) {
  24. return view('passport/logIn');
  25. }
  26. $goodsModel = new GoodsModel();
  27. //$goods['content'] = html_entity_decode($goods['content']);
  28. return view('order', ['goods' => []]);
  29. }
  30. /**
  31. * 我的订单页面
  32. * @return \think\response\View
  33. */
  34. public function order(string $orderType = 'received')
  35. {
  36. $userId = Session::get('user_id');
  37. if (empty($userId)) {
  38. return view('passport/logIn');
  39. }
  40. return view('order');
  41. }
  42. /**
  43. * 订单详情
  44. * @param $orderId
  45. * @return \think\response\View
  46. * @throws \cores\exception\BaseException
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function orderDetails($orderId)
  52. {
  53. $userId = Session::get('user_id');
  54. if (empty($userId)) {
  55. return view('passport/logIn');
  56. }
  57. $model = OrderModel::getUserOrderDetail($orderId);
  58. $orderAddress = OrderAddress::get(['order_id' => $orderId]);
  59. return view('orderDetails', ['order' => $model, 'orderAddress' => $orderAddress]);
  60. }
  61. /**
  62. * 我的积分页面
  63. * @return \think\response\View
  64. */
  65. public function myScores()
  66. {
  67. $userId = Session::get('user_id');
  68. if (empty($userId)) {
  69. return view('passport/logIn');
  70. }
  71. $model = new PointsLogModel;
  72. $list = $model->getList();
  73. $user = \app\index\service\User::getCurrentLoginUser();
  74. return view('integral', ['user' => $user]);
  75. }
  76. /**
  77. * 我的积分列表
  78. * @return \think\response\Json
  79. * @throws \app\common\exception\BaseException
  80. * @throws \think\db\exception\DbException
  81. */
  82. public function pointsLogs()
  83. {
  84. $model = new PointsLogModel;
  85. $list = $model->getList();
  86. return $this->renderSuccess(compact('list'));
  87. }
  88. /**
  89. * 分享商品
  90. * @return \think\response\Json
  91. */
  92. public function shareUser()
  93. {
  94. $userId = Session::get('user_id');
  95. if (empty($userId)) {
  96. return $this->renderJson(config('status.not_logged'), 'Log in please!');
  97. }
  98. $goodsId = $this->request->param('goodsId');
  99. if (empty($goodsId)) {
  100. return $this->renderError('Invalid goods');
  101. }
  102. $mailbox = $this->request->param('mailbox');
  103. if (empty($mailbox)) {
  104. return $this->renderError('Invalid mailbox');
  105. }
  106. $encryptUserId = encrypt(strval($userId));
  107. $url = url('/index/index/productDetail?goodsId=' . $goodsId . '&key=' . $encryptUserId);
  108. //todo 发邮件
  109. $MailCaptchaService = new MailCaptchaService;
  110. if ($MailCaptchaService->sendText($mailbox,'From Your Friend',$url)) {
  111. return $this->renderSuccess('Sent Successful!Please check your new mails.');
  112. }
  113. return $this->renderSuccess([]);
  114. }
  115. }