src/ApiBundle/Api/Resource/Me/MeCoupon.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace ApiBundle\Api\Resource\Me;

use ApiBundle\Api\ApiRequest;
use ApiBundle\Api\Resource\AbstractResource;
use ApiBundle\Api\Annotation\ResponseFilter;
use Biz\Coupon\CouponException;
use Biz\Common\CommonException;

class MeCoupon extends AbstractResource
{
    public function search(ApiRequest $request)
    {
        $conditions = array(
            'userId' => $this->getCurrentUser()->getId(),
            'status' => 'receive',
            'cardType' => 'coupon',
        );

        $myCards = $this->getCardService()->searchCards(
            $conditions,
            array('createdTime' => 'DESC'),
            0,
            PHP_INT_MAX
        );

        return array_values($this->getCouponService()->findCouponsByIds(array_column($myCards, 'cardId')));
    }

    /**
     * @ResponseFilter(class="ApiBundle\Api\Resource\Coupon\CouponFilter", mode="public")
     */
    public function add(ApiRequest $request)
    {
        $user = $this->getCurrentUser();
        $token = $request->request->get('token');
        if (empty($token)) {
            throw CommonException::ERROR_PARAMETER_MISSING();
        }

        if (!$this->isPluginInstalled('coupon')) {
            throw CouponException::PLUGIN_NOT_INSTALLED();
        }
        $result = $this->getCouponBatchService()->receiveCoupon($token, $user['id']);

        if ('success' != $result['code']) {
            if (isset($result['exception'])) {
                $exceptionMethod = $result['exception']['method'];
                throw $result['exception']['class']::$exceptionMethod();
            } else {
                throw CouponException::RECEIVE_FAILED();
            }
        }

        $coupon = $this->getCouponService()->getCoupon($result['id']);
        $coupon['target'] = $this->getCouponService()->getCouponTargetByTargetTypeAndTargetId($coupon['targetType'], $coupon['targetId']);

        return $coupon;
    }

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。