123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Http\Home;
- use App\Services\Eav\MaterialService;
- use App\Services\Elastic\Facades\ES;
- use App\Services\Login\LoginTokenService;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- use Illuminate\Support\Facades\Schema;
- class BuyController extends HttpBaseController
- {
- public function __construct()
- {
- parent::__construct();
- $this->setWebsite(__NAMESPACE__);
- }
- /**
- * 购买
- */
- public function index()
- {
- $isLogin = $this->isLogin();
- $pmid = Request::input('pmid');
- if(empty($pmid)){
- abort(404);
- }
- if ($isLogin) {
- $loginToken = new LoginTokenService($this->siteInfo['token_table']);
- $token = $loginToken->getToken();
- //判断该产品是否存在
- $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first();
- if (empty($productInfo)) {
- abort(404);
- }
- // 获取图片广告
- $ad = DB::table("position_list")
- ->where("group_id", 2)
- ->where('tag', 'buy_box_top_ad')->first();
- // 获取用户信息
- $userInfo = DB::table('user')->find($this->userId);
- unset($userInfo->unionid);
- $billInfo = $this->getUserBill($productInfo->id, $this->userId);
- return view("home/http/buy", ["isLogin" => $isLogin,'token'=>$token, "billInfo" => $billInfo, "userInfo" => $userInfo, "productInfo" => $productInfo, 'ad' => $ad]);
- } else {
- return view("home/http/buy", ["isLogin" => $isLogin]);
- }
- }
- /**
- * 获取购买的产品的账单信息
- */
- 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)->where("is_delete", 0)->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];
- }
- }
|