当前位置:网站首页>edusoho兑换码功能二次开发

edusoho兑换码功能二次开发

2022-08-11 11:27:00 withkai44

功能描述:兑换码,是由一串数字或字母的组合,用户可使用兑换码去兑换网校课程。网校可通过其它流量平台售卖兑换码、印制线下礼品卡等方式,将兑换码发送给用户;
在这里插入图片描述
场景示例:某网校想要拓宽自己的销售渠道,使用兑换码功能,将课程加入到兑换码中,放在淘宝天猫店铺内售卖,用户获得兑换码即可兑换网校课程,网校借助淘宝天猫平台的流量为网校引流,提高销量;

技术支持二次开发QQ: 735660248
<?php

namespace CouponPlugin\Controller;

use AppBundle\Common\ArrayToolkit;
use AppBundle\Common\Paginator;
use AppBundle\Controller\BaseController;
use Biz\Coupon\Service\CouponService;
use Codeages\Biz\Order\Service\OrderService;
use CouponPlugin\Biz\Coupon\Service\CouponBatchService;
use Symfony\Component\HttpFoundation\Request;

class CouponBatchController extends BaseController
{
    
    public function appendAction(Request $request, $batchId)
    {
    
        $batch = $this->getCouponBatchService()->getBatch($batchId);

        if ($request->isMethod('POST')) {
    
            $data = $request->request->all();
            $data['batch'] = $batch;

            $appendBatch = $this->getCouponBatchService()->appendCoupon($batch['id'], $data);
            $data = array(
                'url' => $this->generateUrl('admin_coupon_batch_create', array('batchId' => $batch['id'])),
                'num' => $appendBatch['generatedNum'] - $batch['generatedNum'],
            );

            return $this->createJsonResponse($data);
        }

        return $this->render('CouponPlugin::batch-append-coupon-modal.html.twig', array(
            'batch' => $batch,
        ));
    }

    public function checkNumAction(Request $request, $batchId)
    {
    
        $appendNum = $request->query->get('value');

        $batch = $this->getCouponBatchService()->getBatch($batchId);
        $remain = CouponBatchService::BATCH_COUPON_MAX_NUM - $batch['generatedNum'];

        if ($appendNum > $remain) {
    
            $response = array('success' => false, 'message' => '当前批次优惠券数量已达到最大值,请重新创建优惠券批次');
        } else {
    
            $response = array('success' => true, 'message' => '');
        }

        return $this->createJsonResponse($response);
    }

    public function detailAction(Request $request, $batchId)
    {
    
        $count = $this->getCouponService()->searchCouponsCount(array('batchId' => $batchId));

        $batch = $this->getCouponBatchService()->getBatch($batchId);

        $paginator = new Paginator($this->get('request'), $count, 20);

        $coupons = $this->getCouponService()->searchCoupons(
            array('batchId' => $batchId),
            array('orderTime' => 'DESC', 'id' => 'ASC'),
            $paginator->getOffsetCount(),
            $paginator->getPerPageCount()
        );
        $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($coupons, 'userId'));

        $orders = $this->getOrderService()->findOrdersByIds(ArrayToolkit::column($coupons, 'orderId'));

        return $this->render('CouponPlugin:coupon:coupon-modal.html.twig', array(
            'coupons' => $coupons,
            'batch' => $batch,
            'paginator' => $paginator,
            'users' => $users,
            'orders' => ArrayToolkit::index($orders, 'id'),
        ));
    }

    public function logAction(Request $request, $batchId)
    {
    
        $count = $this->getCouponBatchService()->countBatchLog(array('batchId' => $batchId));

        $paginator = new Paginator($this->get('request'), $count, 20);

        $batchLogs = $this->getCouponBatchService()->searchBatchLog(
            array('batchId' => $batchId),
            array('createdTime' => 'DESC'),
            $paginator->getOffsetCount(),
            $paginator->getPerPageCount()
        );

        $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($batchLogs, 'userId'));

        return $this->render('CouponPlugin:coupon:coupon-log-tab.html.twig', array(
            'batchLogs' => $batchLogs,
            'paginator' => $paginator,
            'users' => $users,
        ));
    }

    /** * @return CouponService */
    private function getCouponService()
    {
    
        return $this->createService('Coupon:CouponService');
    }

    /** * @return CouponBatchService */
    protected function getCouponBatchService()
    {
    
        return $this->createService('CouponPlugin:Coupon:CouponBatchService');
    }

    /** * @return OrderService */
    private function getOrderService()
    {
    
        return $this->createService('Order:OrderService');
    }
}

在这里插入图片描述

原网站

版权声明
本文为[withkai44]所创,转载请带上原文链接,感谢
https://blog.csdn.net/withkai44/article/details/126244651