BuyController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Home;
  3. use App\Services\Eav\MaterialService;
  4. use App\Services\Elastic\Facades\ES;
  5. use App\Services\Login\LoginTokenService;
  6. use Illuminate\Database\Schema\Blueprint;
  7. use Illuminate\Support\Carbon;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Request;
  10. use Illuminate\Support\Facades\Schema;
  11. class BuyController extends HttpBaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->setWebsite(__NAMESPACE__);
  17. }
  18. /**
  19. * 购买
  20. */
  21. public function index()
  22. {
  23. $isLogin = $this->isLogin();
  24. $pmid = Request::input('pmid');
  25. if(empty($pmid)){
  26. abort(404);
  27. }
  28. if ($isLogin) {
  29. $loginToken = new LoginTokenService($this->siteInfo['token_table']);
  30. $token = $loginToken->getToken();
  31. //判断该产品是否存在
  32. $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
  33. if (empty($productInfo)) {
  34. abort(404);
  35. }
  36. // 获取图片广告
  37. $ad = DB::table("position_list")
  38. ->where("group_id", 2)
  39. ->where('tag', 'buy_box_top_ad')->first();
  40. // 获取用户信息
  41. $userInfo = DB::table('user')->find($this->userId);
  42. unset($userInfo->unionid);
  43. $billInfo = $this->getUserBill($productInfo->id, $this->userId);
  44. return view("home/http/buy", ["isLogin" => $isLogin,'token'=>$token, "billInfo" => $billInfo, "userInfo" => $userInfo, "productInfo" => $productInfo, 'ad' => $ad]);
  45. } else {
  46. return view("home/http/buy", ["isLogin" => $isLogin]);
  47. }
  48. }
  49. /**
  50. * 获取购买的产品的账单信息
  51. */
  52. private function getUserBill($productId, $userId)
  53. {
  54. // 获取该产品的支付信息
  55. $validity_type = 0;
  56. $validity_end_time = "";
  57. $billInfo = DB::table("user_buy_bill")->where("product_id", $productId)->where("user_id", $userId)->where("is_delete", 0)->first();
  58. if ($billInfo) {
  59. if ($billInfo->validity_type == 2) {
  60. // 永久有效
  61. $validity_type = 2;
  62. } else if ($billInfo->validity_type == 1) {
  63. // // 时间有效期
  64. $end_time = $billInfo->validity_end_time;
  65. if (time() < $end_time) {
  66. $validity_type = 1;
  67. $validity_end_time = date('Y-m-d H:i:s', $end_time);
  68. }
  69. }
  70. }
  71. return ["validity_type" => $validity_type, "validity_end_time" => $validity_end_time];
  72. }
  73. }