123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Http\Api;
- use Illuminate\Support\Facades\DB;
- class ProductController extends HttpBaseController
- {
- public function __construct()
- {
- parent::__construct();
- $this->setWebsite(__NAMESPACE__);
- $this->isLoginJson();
- }
- /**
- * 点击用户名称的时候 获取用户的账单信息
- */
- public function userBill($pmid)
- {
- //判断该产品是否存在
- $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
- if (empty($productInfo)) {
- return responseMessage(2001, "产品不存在");
- }
- $billInfo = $this->getUserBill($productInfo->id, $this->userId);
- return responseMessage(1001, "success", $billInfo);
- }
- /**
- * 获取购买的产品的账单信息
- */
- private function getUserBill($productId, $userId)
- {
- // 获取该产品的支付信息
- $validity_type = 0;
- $validity_end_time = "";
- $billInfo = DB::table("user_buy_bill")->where("product_id", $productId)->where("user_id", $userId)->first();
- if ($billInfo) {
- if ($billInfo->validity_type == 2) {
- // 永久有效
- $validity_type = 2;
- } else if ($billInfo->validity_type == 1) {
- // // 时间有效期
- $end_time = $billInfo->validity_end_time;
- if (time() < $end_time) {
- $validity_type = 1;
- $validity_end_time = date('Y-m-d H:i:s', $end_time);
- }
- }
- }
- return ["validity_type" => $validity_type, "validity_end_time" => $validity_end_time];
- }
- }
|