User.php 4.6 KB

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