* @date 2020-01-29 10:13:09 */ declare (strict_types=1); namespace Modules\Api\Controllers; use App\Repositories\Service\PaymentService; use App\Repositories\VipRepository; use Hyperf\Validation\Contract\ValidatorFactoryInterface; use App\Repositories\UserRepository; class VipController extends BaseController { use \Hyperf\Di\Aop\ProxyTrait; use \Hyperf\Di\Aop\PropertyHandlerTrait; function __construct() { if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args()); } $this->__handlePropertyHandler(__CLASS__); } /** * VIP套餐信息 * @param VipRepository $vipRepository * @return mixed */ public function lists(VipRepository $vipRepository) { $userInfo = make(UserRepository::class)->getUserInfoFromCache($this->getUserId()); $result = ['plans' => [], 'ad' => []]; $packages = $vipRepository->getVipPackage($userInfo['coins'], $userInfo['device_type']); $result['plans'] = $packages; return json_success($result); } /** * 购买vip套餐 * @param VipRepository $vipRepository * @return mixed */ public function buyvip(VipRepository $vipRepository) { $inputData = $this->getJsonData(); $rules = ['vip_id' => 'required|integer', 'pay_id' => 'required|integer', 'pay_type' => 'required|integer']; $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $inputData['user_id'] = $this->getUserId(); $inputData['order_type'] = 1; if ($inputData['pay_type'] == 4) { $order = $vipRepository->createCoinVipOrder($inputData); if ($order) { return json_success('vip购买成功'); } } else { $order = $vipRepository->createVipOrder($inputData); if ($order) { //去生成支付链接 $payLink = make(PaymentService::class)->getGateway($order, $inputData['pay_id']); if (!empty($payLink)) { $data = array('jump' => 'y', 'link' => checkPayUrl($payLink)); return json_success($data); } } } return json_fail('亲,请重试'); } /** * VIP结构的jdata独立给android的接口 * @return mixed */ public function vipJdata() { $vipRepo = make(VipRepository::class); $userInfo = make(UserRepository::class)->getUserInfoData($this->getUserId()); $packages = $vipRepo->getVipPackage($userInfo['coins']); $result = []; if (!empty($packages)) { foreach ($packages as $item) { $result[] = $item['jdata']; } } return json_success($result); } }