You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/wap/model/topic/CertificateRecord.php

115 lines
3.9 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\model\topic;
use traits\ModelTrait;
use basic\ModelBasic;
use service\UtilService as Util;
use app\wap\model\user\User;
use app\wap\model\special\Special;
use app\wap\model\topic\TestPaper;
use app\wap\model\topic\Certificate;
use app\wap\model\topic\ExaminationRecord;
/**
* 证书获取记录 Model
* Class CertificateRecord
*/
class CertificateRecord extends ModelBasic
{
use ModelTrait;
/**查询条件
* @param $uid
* @return CertificateRecord
*/
public static function setWhere($uid)
{
$model = self::where(['status' => 1, 'is_del' => 0, 'uid' => $uid]);
return $model;
}
/**获得证书列表
* @param $uid
* @param $page
* @param $limit
*/
public static function getUserCertificate($uid, $page, $limit)
{
$list = self::setWhere($uid)->page((int)$page, (int)$limit)->select();
$list = count($list) > 0 ? $list->toArray() : [];
foreach ($list as $key => &$value) {
$value['content'] = self::certificate($value['source_id'], $value['obtain']);
}
return $list;
}
public static function certificate($source_id, $obtain)
{
switch ($obtain) {
case 1:
return Special::where(['id' => $source_id])->field('title,image')->find();
break;
case 2:
return TestPaper::alias('t')->join('ExaminationRecord e', 't.id=e.test_id')
->where(['t.id' => $source_id, 'is_submit' => 1])->order('e.id desc')
->field('t.title,t.item_number,e.wrong_question,e.duration')->find();
break;
}
}
/**获取证书信息
* @param $id
* @param $obtain
* @param $uid
* @return array|bool|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function getCertificate($id, $obtain, $uid)
{
$certificate = self::setWhere($uid)->where(['id' => $id, 'obtain' => $obtain])->find();
if (!$certificate) return [];
$certificate['certificate'] = Certificate::getone($certificate['cid'], $obtain);
return $certificate;
}
/**领取证书
* @param $id
*/
public static function getUserTheCertificate($id, $obtain, $uid)
{
$cid = CertificateRelated::where(['related' => $id, 'obtain' => $obtain, 'is_show' => 1])->value('cid');
if (!$cid) return false;
$record = self::setWhere($uid)->where(['source_id' => $id, 'obtain' => $obtain])->find();
if ($record) return false;
$nickname = User::where('uid', $uid)->value('nickname');
$data = [
'cid' => $cid,
'uid' => $uid,
'nickname' => $nickname,
'source_id' => $id,
'obtain' => $obtain,
'status' => 1,
'add_time' => time()
];
$res = self::insertGetId($data);
$res1 = false;
if ($res) {
$res1 = Certificate::where('id', $cid)->setInc('number');
}
if ($res && $res1) return $res;
else return false;
}
}