瀏覽代碼

证书领取

赵启卫 2 年之前
父節點
當前提交
d3b851efa4
共有 2 個文件被更改,包括 268 次插入3 次删除
  1. 114 1
      application/wap/controller/Studyplan.php
  2. 154 2
      application/wap/view/first/studyplan/details.html

+ 114 - 1
application/wap/controller/Studyplan.php

xqd xqd xqd
@@ -19,10 +19,15 @@ use app\admin\model\study\PlanItems;
 use app\wap\model\special\Special as SpecialModel;
 use app\wap\model\special\SpecialWatch as SpecialWatch;
 use app\wap\model\special\SpecialTask;
+
 use app\admin\model\questions\Relation;
 use app\wap\model\topic\ExaminationRecord;
+use app\wap\model\topic\CertificateRelated;
+use app\wap\model\topic\CertificateRecord;
 use app\wap\model\special\SpecialSource;
 use app\wap\model\store\StoreOrder;
+
+
 use service\JsonService;
 use think\Url;
 
@@ -245,7 +250,6 @@ class Studyplan extends AuthController{
         }
         if (!$nowspid) {
             $nowspid = $items[0]['id'];
-            print_r($tasklist);
             $nowtaskid = $tasklist[$nowspid][0]['source_id'];
         }
         //id=206&specialId=37&viewing_time=0
@@ -264,4 +268,113 @@ class Studyplan extends AuthController{
             return JsonService::fail();
     }
 
+    /**
+     * 学习计划检测是否达到领取证书标准
+     * $plan_id 学习计划ID
+     */
+    public function inspect($plan_id = 0)
+    {
+        if (!$this->uid) return JsonService::fail('err');
+        if (!$plan_id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
+        $planinfo = Plan::get($plan_id);
+        if (!$planinfo) $this->failed('参数错误,无法访问', Url::build('index/index'));
+        $buyinfo = PlanBuy::where('planid', $plan_id)->where('uid', $this->uid)->where('is_del', 0)->find();
+        if (!$buyinfo) {
+            $this->failed('课程尚未购买,非法访问', Url::build('index/index'));
+        }
+        //查询是否关联证书
+        $certinfo = CertificateRelated::where(['related' => $plan_id, 'obtain' => 3, 'is_show' => 1])->find();
+        if (!$certinfo) $this->failed('该学习计划未绑定证书');
+        //查询是否以获得证书
+        $certinfo = CertificateRecord::where(['source_id' => $plan_id, 'obtain' => 3, 'status' => 1, 'uid' => $this->uid])->find();
+        if ($certinfo) $this->failed('学习计划证书已获取完成');
+
+
+        $steps = PlanSteps::where('is_del', 0)->where('pid', $plan_id)->order('sort asc')->select();
+        foreach($steps as $v){
+            $stepids[] = $v['id'];
+        }
+        $join = [
+            ['special s', 's.id = it.cid and s.is_del = 0 and s.status = 1'],
+        ];
+        $items = PlanItems::alias('it')->field('s.*, it.stepsid,it.pid, it.cid')
+            ->join($join)
+            ->where('pid', $plan_id)
+            ->where('stepsid', 'in', $stepids)
+            ->order('sort asc')
+            ->select();
+        //$spids = [];
+        $flag = 1;
+        $itemsList = [];
+        $tasklist = [];
+        foreach ($items as $v) {
+            $v['count'] = SpecialModel::numberChapters($v['type'], $v['id']);
+            $itemsList[$v['stepsid']][] = $v->toArray();
+            //$spids[] = $v['cid'];
+            $join = [
+                ['SpecialWatch sw', 'sw.special_id = ss.special_id and sw.task_id = ss.source_id and sw.uid = ' . $this->uid, 'left'],
+            ];
+            $order = 'sort desc,id desc';
+            if ($v['sort_order']) {
+                $order = 'sort asc, id asc';
+            }
+            $specialWatchList = SpecialSource::alias('ss')->field('ss.*, sw.viewing_time,sw.percentage')
+                ->join($join)
+                ->where('ss.special_id', '=', $v['cid'])
+                ->order($order)
+                ->select();
+            foreach($specialWatchList as $v){
+                $tasklist[$v['special_id']][] = $v->toArray();
+            }
+        }
+        
+        
+        $nowspid = 0;
+        foreach ($itemsList as $v) {
+            foreach ($v as $v1) {
+                //判断课程是否学习完成
+                if ($tasklist[$v1['id']] && is_array($tasklist[$v1['id']])) {
+                    foreach ($tasklist[$v1['id']] as $v2) {
+                        if ($v2['percentage'] < 100) {
+                            $nowspid = $v1['id'];
+                            $flag = 0;
+                            break;
+                        }
+                    }
+                }
+                if ($nowspid) break;
+                //判断是否有考试
+                $join = [
+                    ['ExaminationRecord er', 'er.test_id = r.relation_id and er.uid = ' . $this->uid, 'left'],
+                ];
+                $examlist = Relation::alias('r')->where('r.relationship_id', $v1['id'])->where('r.relationship', 2)
+                ->field('r.relation_id as test_id, er.score')->join($join)->select();
+                if ($examlist) {
+                    foreach ($examlist as $item) {
+                        if ($item['score'] < 60) {
+                            $flag = 0;
+                        }
+                    }
+                }
+                
+            }
+            if ($nowspid) break;
+        }
+        if ($flag) {
+            return JsonService::successful('ok');
+        } else {
+            return JsonService::fail('err');
+        }
+    }
+
+    /**用户领取证书
+     * $special_id 专题ID
+     */
+    public function getTheCertificate($plan_id)
+    {
+        $res = CertificateRecord::getUserTheCertificate($plan_id, 3, $this->uid);
+        if ($res) return JsonService::successful($res);
+        else return JsonService::fail('领取失败');
+    }
+
 }

+ 154 - 2
application/wap/view/first/studyplan/details.html

xqd xqd xqd xqd xqd xqd
@@ -65,6 +65,15 @@
         height: 0.76rem;
         border-radius: 37px;
     }
+    .certificate-image {
+        position: fixed;
+        top: 50%;
+        left: 50%;
+        z-index: 56;
+        width: 6rem;
+        -webkit-transform: translate(-50%, -50%);
+        transform: translate(-50%, -50%);
+    }
 </style>
 {/block}
 {block name="content"}
@@ -143,6 +152,8 @@
             </div>
         </div>
     </footer>
+    <!-- 遮罩层 -->
+    <div :class="{ mask: dialogShow || password || is_poster || imgSrc || !open }" @touchmove.prevent @click="maskClick"></div>
     <!-- 支付弹窗 -->
     <pay-dialog :open.sync="payDialogOpen" :money="money" :now_money="now_money" :special_id="planinfo.id" :link_pay_uid="link_pay_uid"
                 :pay_type_num="pay_type_num" :pink-id="pinkId" :is-wechat="isWechat" :is-alipay="is_alipay" :is-balance="is_yue"
@@ -150,13 +161,15 @@
     </pay-dialog>
     <!-- 登录弹窗 -->
     <base-login :login-show="loginShow" :site-name="site_name" @login-close="loginClose"></base-login>
+    <!-- 完课证书 -->
+    <img v-if="imgSrc" :src="imgSrc" class="certificate-image">
 </div>
 {/block}
 {block name="foot"}
 <script>
     require(['vue', 'store', 'helper', '{__WAP_PATH}zsff/js/quick.js', 
-    'components/pay-dialog/index', 'components/base-login/index'], 
-    function (Vue, store, $h, quick, PayDialog, BaseLogin) {
+    'components/pay-dialog/index', 'components/base-login/index', 'axios', 'moment'], 
+    function (Vue, store, $h, quick, PayDialog, BaseLogin, axios, moment) {
         var planinfo = {$planinfo};
         var steps = {$steps};
         var itemsList = {$itemsList};
@@ -198,11 +211,17 @@
                 isMember:isMember,
                 site_name:site_name,
                 orderId:'',
+                imgSrc:'',
+                dialogShow:false,
+                password:'',
+                is_poster:'',
+
             },
             mounted: function () {
                 this.$nextTick(function () {
                     this.init();
                 });
+                this.getInspect();
             },
             methods: {
                 init: function () {
@@ -211,6 +230,14 @@
                 study: function (){
                     return window.location.href=$h.U({ c: 'studyplan', a: 'gotoStudy', q: {id: this.planinfo.id } });
                 },
+                // 点击遮罩层
+                maskClick: function () {
+                    this.dialogShow = false;
+                    this.password = false;
+                    this.is_poster = false;
+                    this.open = true;
+                    this.imgSrc = '';
+                },
                 //关闭登录
                 loginClose: function (val) {
                     this.loginShow = false;
@@ -341,6 +368,131 @@
                         vm.loginShow = true;
                     });
                 },
+
+                // 是否可以发放证书
+                getInspect: function () {
+                    var that = this;
+                    $h.loadFFF();
+                    axios.get($h.U({
+                        c: 'studyplan',
+                        a: 'inspect',
+                        q: {
+                            plan_id: this.planinfo.id
+                        }
+                    })).then(function (res) {
+                        $h.loadClear();
+                        if (200 == res.data.code) {
+                            layer.confirm('恭喜您已达到证书发放标准,是否领取?', {
+                                title: false,
+                                closeBtn: false,
+                                btn: ['领取', '取消']
+                            }, function (index) {
+                                that.getCertificate();
+                                layer.close(index);
+                            });
+                        }
+                    }).catch(function () {
+                        $h.loadClear();
+                    });
+                },
+                // 领取证书
+                getCertificate: function () {
+                    $h.loadFFF();
+                    store.baseGet($h.U({
+                        c: 'studyplan',
+                        a: 'getTheCertificate',
+                        q: {
+                            plan_id: this.planinfo.id
+                        }
+                    }), function (res) {
+                        $h.loadClear();
+                        layer.msg('领取成功<br>证书制作中…', function () {
+                            this.getCertificateInfo(res.data.msg);
+                        }.bind(this));
+                    }.bind(this), function () {
+                        $h.loadClear();
+                    });
+                },
+                // 获取证书信息
+                getCertificateInfo: function (id) {
+                    $h.loadFFF();
+                    store.baseGet($h.U({
+                        c: 'topic',
+                        a: 'viewCertificate',
+                        q: {
+                            id: id,
+                            obtain: 3
+                        }
+                    }), function (res) {
+                        $h.loadClear();
+                        this.createCertificate(res.data.data);
+                    }.bind(this), function (err) {
+                        $h.loadClear();
+                        console.error(err);
+                    });
+                },
+                // 加载图片
+                loadImage: function (path) {
+                    return new Promise(function (resolve, reject) {
+                        var image = new Image();
+                        image.crossOrigin = 'anonymous';
+                        image.onload = function () {
+                            resolve(image);
+                        };
+                        image.onerror = function () {
+                            reject('error-image');
+                        };
+                        image.src = path + '?' + new Date().getTime();
+                    });
+                },
+                // 生成证书图片
+                createCertificate: function (certificate) {
+                    $h.loadFFF();
+                    Promise.all([
+                        this.loadImage(certificate.certificate.background),
+                        this.loadImage(certificate.certificate.qr_code)
+                    ]).then(function (images) {
+                        var canvas = document.createElement('canvas');
+                        var context = canvas.getContext('2d');
+
+                        canvas.width = images[0].width;
+                        canvas.height = images[0].height;
+
+                        context.drawImage(images[0], 0, 0);
+                        context.drawImage(images[1], 220, 557, 160, 160);
+
+                        context.fillStyle = 'rgba(255, 255, 255, 1)';
+                        context.fillRect(220, 724, 160, 36);
+
+                        context.font = '20px sans-serif';
+                        context.textAlign = 'center';
+                        context.fillStyle = '#666666';
+                        context.fillText('长按二维码查看', 300, 748);
+
+                        context.font = 'bold 34px sans-serif';
+                        context.fillStyle = '#29466D';
+                        context.fillText(certificate.nickname, 300, 296);
+
+                        context.font = '24px sans-serif';
+                        context.fillText('颁发时间:' + moment(certificate.add_time * 1000).format('YYYY.MM.DD'), 300, 481);
+
+                        context.font = '28px sans-serif';
+                        context.textAlign = 'start';
+                        context.fillStyle = '#333333';
+
+                        for (var i = Math.ceil(certificate.certificate.explain.length % 16); i--;) {
+                            context.fillText(certificate.certificate.explain.substr(i * 16, 16), 83, i * 40 + 370);
+                        }
+
+                        this.imgSrc = canvas.toDataURL('image/jpeg');
+                        canvas = null;
+                        $h.loadClear();
+                    }.bind(this)).catch(function (error) {
+                        $h.loadClear();
+                        console.error(error);
+                    });
+                },
+
             }
         });
     });