User.php 3.9 KB

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