<?php /** * Created by PhpStorm. * User: zhoutao * Date: 2017/12/21 * Time: 下午6:06 */ namespace Apicp\Controller\Pay; use Common\Common\Order; use VcySDK\CyPay; use VcySDK\Service; class GetVipRuleController extends AbstractController { protected $needCheckThePayment = false; /** * 规则类型与UC支付类型映射 */ const RULE_TYPE_MAPPING_ORDER_TYPE = [ // 购买员圈应用 1 => 4, // 购买空间 2 => 6, // 购买流量 3 => 6, // 扩充人数 4 => 5, ]; /** * 支付状态:待支付 */ const ORDER_STATUS_WAIT_PAY = 1; /** * 是否存在待支付订单:不存在 */ const ORDER_WAIT_PAY_NO = 1; /** * 是否存在待支付订单:存在 */ const ORDER_WAIT_PAY_YES = 2; /** * 规则类型:扩充人数 */ const PAY_RULE_ADD_USER = 4; /** * GetVipRule * @author tangxingguo * @desc 获取付费规则,返回结果说明:该返回数据格式仅针对提交了rule_type的情况 * @param Int rule_type 规则类型(1=续费;2=空间容量;3=流量;4=扩充人数) * @return array * array( * 'is_wait_pay' => 1, // 是否存在待支付订单(1=无;2=有) * 'product_id' => '008474BE7F00000175505861C25D23D2', // 产品类型 * 'product_name' => '扩充人数', // 产品名称 * 'current_people' => 100, // 当前应用授权使用人数 * 'order_id' => '045EA0FC7F0000011C8D0FD226E592F3', // 待支付订单ID * 'expire_time' => 1521561599000, // 当前生效订单失效期,扩充人数时有值 * 'rule' => array( // 付费规则 * array( * 'networkRule' => array( * 'price' => 8800, * 'network' => 107374182400, * 'unit' => 'G', * ) * ) * ) * ); */ public function index() { // 请求数据 $postData = I('post.'); // 规则 $sdk = new CyPay(Service::instance()); $rule = $sdk->getVipRule(); if (isset($postData['rule_type'])) { // 同类待支付订单确认 $orderMap = self::RULE_TYPE_MAPPING_ORDER_TYPE; $orderServ = &Order::instance(); // 获取当前应用授权使用人数 $allow_users = $orderServ->GetAllowUserTotal(['plIdentifier' => 'yuanquan']); $orderList = $orderServ->fetchOrderList([ 'ordPayStatus' => self::ORDER_STATUS_WAIT_PAY, 'ordType' => $orderMap[$postData['rule_type']], ]); // 扩充人数,需要获取当前生效订单有效期限 if ($postData['rule_type'] == self::PAY_RULE_ADD_USER) { // 可使用订单列表(包括正在生效的订单) $list = $orderServ->fetchValidOrderList(['ordType' => 4]); // 获取当前生效订单的失效时间 if (isset($list['total']) && $list['total'] > 0) { $orderInfo = reset($list['list']); $oauEnd = $orderInfo['oauEnd']; } } $this->_result = [ 'is_wait_pay' => $orderList['total'] > 0 ? self::ORDER_WAIT_PAY_YES : self::ORDER_WAIT_PAY_NO, 'product_id' => $orderList['total'] > 0 ? $orderList['list'][0]['prId'] : '', 'product_name' => $orderList['total'] > 0 ? $orderList['list'][0]['ordTitle'] : '', 'current_people' => intval($allow_users['memberTotal']), 'order_id' => $orderList['total'] > 0 ? $orderList['list'][0]['ordId'] : '', 'expire_time' => isset($oauEnd) ? $oauEnd : 0, 'rule' => $rule, ]; return true; } $this->_result = $rule; } }