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; } }