• edusoho兑换码功能二次开发


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

    技术支持二次开发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');
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126

    在这里插入图片描述

  • 相关阅读:
    Postman接口断言&上下游参数传递
    京东API接口详情
    使用设计模式基于easypoi优雅的设计通用excel导入功能
    工程师如何对待开源 --- 一个老工程师的肺腑之言
    039_小驰私房菜_Camera perfermance debug
    技术干货 | 数据处理好难?来看MindSpore提供的解决思路!
    (附源码)ssm捐赠救助系统 毕业设计 060945
    [Kubernetes] 多调度器(1/3):如何编译scheduler,以默认调度器 kube-scheduler为例
    Error: Fail to open IDE
    利率里面的BP是什么意思,基准利率bp是什么意思
  • 原文地址:https://blog.csdn.net/withkai44/article/details/126244651