ProductController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Api;
  3. use Illuminate\Support\Facades\DB;
  4. class ProductController extends HttpBaseController
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->setWebsite(__NAMESPACE__);
  10. $this->isLoginJson();
  11. }
  12. /**
  13. * 点击用户名称的时候 获取用户的账单信息
  14. */
  15. public function userBill($pmid)
  16. {
  17. //判断该产品是否存在
  18. $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
  19. if (empty($productInfo)) {
  20. return responseMessage(2001, "产品不存在");
  21. }
  22. $billInfo = $this->getUserBill($productInfo->id, $this->userId);
  23. return responseMessage(1001, "success", $billInfo);
  24. }
  25. /**
  26. * 获取购买的产品的账单信息
  27. */
  28. private function getUserBill($productId, $userId)
  29. {
  30. // 获取该产品的支付信息
  31. $validity_type = 0;
  32. $validity_end_time = "";
  33. $billInfo = DB::table("user_buy_bill")->where("product_id", $productId)->where("user_id", $userId)->first();
  34. if ($billInfo) {
  35. if ($billInfo->validity_type == 2) {
  36. // 永久有效
  37. $validity_type = 2;
  38. } else if ($billInfo->validity_type == 1) {
  39. // // 时间有效期
  40. $end_time = $billInfo->validity_end_time;
  41. if (time() < $end_time) {
  42. $validity_type = 1;
  43. $validity_end_time = date('Y-m-d H:i:s', $end_time);
  44. }
  45. }
  46. }
  47. return ["validity_type" => $validity_type, "validity_end_time" => $validity_end_time];
  48. }
  49. }