Commit fd62cef4 authored by wangzhengwen's avatar wangzhengwen

证书模块

parent 1a5861f2
......@@ -79,7 +79,10 @@ class Course extends BaseController
}
$data = $request->param();
$list = (new CourseModel())->getCourseList($data['category_id']);
$page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10);
$list = (new CourseModel())->getCourseList($data['category_id'],$page,$pageSize);
return $this->returnMsg('success',1,$list);
......
......@@ -13,7 +13,7 @@ class System extends BaseController
*/
public function getBannerList()
{
$list = AdvertCate::where(['position'=>1,'is_show'=>1])
$list = AdvertCate::where(['position'=>1,'is_show'=>1,'is_del'=>0])
->with(['getAdvertList'=>['coverImg']])
->find()
->toArray();
......
<?php
namespace app\api\controller\cert;
use app\api\validate\CertValidate;
use app\BaseController;
use app\model\CertCategory;
use app\model\CertOrder;
use think\Request;
use app\model\Cert as CertModel;
class Cert extends BaseController
{
//项目分类列表
public function getCertCategoryList()
{
$list = (new CertCategory())->getCertCategoryList();
return $this->returnMsg('success',1,$list);
}
//项目列表
public function getCertList(Request $request)
{
$vo = (new CertValidate())->goCheck(['category_id','type']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10);
$list = (new CertModel())->getCertList($data['category_id'],$page,$pageSize,$data['type']);
return $this->returnMsg('success',1,$list);
}
//认证动态
public function getLatestCertList(Request $request)
{
$page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10);
$list = (new CertOrder())->latestCertList($page,$pageSize);
return $this->returnMsg('success',1,$list);
}
//详情
public function getDetailCert(Request $request)
{
$vo = (new CertValidate())->goCheck(['cert_id']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$detail = CertModel::where('id',$data['cert_id'])
->append(['starttimetxt','endtimetxt'])
->find();
return $this->returnMsg('success',1,$detail);
}
}
\ No newline at end of file
<?php
namespace app\api\controller\cert;
use app\api\middleware\Auth;
use app\api\service\UtilService;
use app\api\validate\CertValidate;
use app\BaseController;
use think\queue\Queueable;
use think\Request;
use app\model\CertOrder as OrderModel;
class CertOrder extends BaseController
{
protected $middleware = [
Auth::class,
];
//报名
public function enrollCert(Request $request)
{
$allowArray = ['cert_id','name','idcard','idcard_q','idcard_h','mobile','email','head_img_id','other_file_id','pay_type'];
$vo = (new CertValidate())->goCheck($allowArray);
if ($vo !== true) {
return $vo;
}
$data = $request->only($allowArray);
$data['user_id'] = $request->userId;
$data['createtime'] = time();
// $data['order_sn'] = UtilService::generateOrderNo($request->userId,'cert');
unset($data['pay_type']);
$where = ['is_del'=>0,'user_id'=>$data['user_id'],'cert_id'=>$data['cert_id']];
$count = OrderModel::where($where)->count();
if ($count > 0) {
return $this->returnMsg('请勿重复提交');
}
$enrollCert = OrderModel::create($data);
return $this->returnMsg('success',1,$enrollCert);
}
}
\ No newline at end of file
......@@ -4,5 +4,18 @@ namespace app\api\service;
class UtilService
{
public static function generateOrderNo($userId = 0,$str=null)
{
$microtime = microtime(true);
$timestamp = date('YmdHis') . substr($microtime, 11, 3);
$random = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
$userPart = $userId ? substr(str_pad($userId, 4, '0', STR_PAD_LEFT), -4) : '';
return $str.'-'. $timestamp . $random . ($userPart ? ('-' . $userPart) : '');
}
}
\ No newline at end of file
<?php
namespace app\api\validate;
class CertValidate extends BaseValidate
{
protected $rule = [
'searchKeyWords' => 'require',
'category_id' => 'require|number',
'cert_id' => 'require|number',
'type' => 'require|number',
'name' => 'require',
'idcard' => 'require|number',
'idcard_q' => 'require|number',
'idcard_h' => 'require|number',
'mobile' => 'require|mobile',
'email' => 'require|email',
'head_img_id' => 'require|number',
'other_file_id' => 'require|number',
'pay_type'=>'require|number',
];
}
\ No newline at end of file
......@@ -53,11 +53,94 @@ class Cert extends Model
public function certcatedata()
{
return $this->hasOne(CertCategory::class, 'id', 'cate_id')
->field('id,title');
}
/**分类下的项目列表
* @param $category_id
* @param $page
* @param $pageSize
* @param $type 1 普通列表 2即将开始
* @return array|\think\Paginator
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCertList($category_id,$page,$pageSize,$type)
{
$where = ['is_sell' => 1, 'is_del' => 0];
if ($category_id) {
$where['cate_id'] = $category_id;
}
$query = self::where($where);
if ($type == 2) {
$currentTime = time();
$query->where('start_time', '<=', $currentTime)
->where('end_time', '>=', $currentTime);
$query->order('end_time','asc');
}else{
$query->order('createtime','desc');
}
$list = $query->field('id,thumb_id,title,createtime,description,shrq,fzjg,price,tag_ids,start_time,end_time')
->paginate([
'page' => $page,
'list_rows' => $pageSize
]);
if ($list->isEmpty() || $type==2) {
return $list;
}
// 收集所有tag_ids
$allTagIds = [];
foreach ($list->items() as $item) {
if (!empty($item->tag_ids)) {
$tagIds = explode(',', $item->tag_ids);
$allTagIds = array_merge($allTagIds, $tagIds);
}
}
// 批量查询所有标签
$tags = [];
if (!empty($allTagIds)) {
$tags = CertTag::where('is_del', 0)
->whereIn('id', array_unique($allTagIds))
->field('id,title')
->select()
->toArray();
$tags = array_column($tags, null, 'id');
}
// 组装结果
$result = $list->toArray();
foreach ($result['data'] as &$item) {
$itemTags = [];
if (!empty($item['tag_ids'])) {
$tagIds = explode(',', $item['tag_ids']);
foreach ($tagIds as $tagId) {
if (isset($tags[$tagId])) {
$itemTags[] = $tags[$tagId];
}
}
}
$item['tags'] = $itemTags;
}
return $result;
}
}
\ No newline at end of file
......@@ -38,6 +38,25 @@ class CertCategory extends Model
return get_upload_file($data['thumb']);
}
public function children()
{
return $this->hasMany(CertCategory::class, 'pid');
}
public function getCertCategoryList()
{
$where[] = ['is_del', '=', 0];
return $this->with(['children' => function($query) use($where) {
$query->where($where);
$query->order('sort', 'asc');
}])
->where('pid', 0)
->where($where)
->order('sort', 'asc')
->select();
}
}
\ No newline at end of file
......@@ -54,4 +54,64 @@ class CertOrder extends Model
return $statustxt;
}
//最新认证动态
public function latestCertList($page,$pageSize)
{
$where = ['status'=>3,'is_del'=>0];
$list = self::where($where)
->with(['user'=>['headico'],'cert'])
->order('createtime','desc')
->field('id,cert_id,user_id,name,updatetime')
->paginate([
'page' => $page,
'list_rows' => $pageSize
]);
$list->each(function($item) {
$item->append(['updatetime_text']);
return $item;
});
return $list;
}
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id')->field('id,username,headico');
}
public function cert()
{
return $this->hasOne(Cert::class, 'id', 'cert_id')->field('id,title');
}
public function getUpdatetimeTextAttr($value, $data)
{
$timestamp = is_numeric($data['updatetime']) ? $data['updatetime'] : strtotime($data['updatetime']);
return $this->timeElapsedString($timestamp);
}
protected function timeElapsedString($timestamp)
{
$currentTime = time();
$timeDiff = $currentTime - $timestamp;
if ($timeDiff < 60) {
return '刚刚';
} elseif ($timeDiff < 3600) {
return floor($timeDiff / 60) . '分钟前';
} elseif ($timeDiff < 86400) {
return floor($timeDiff / 3600) . '小时前';
} elseif ($timeDiff < 2592000) {
return floor($timeDiff / 86400) . '天前';
} elseif ($timeDiff < 31536000) {
return floor($timeDiff / 2592000) . '个月前';
} else {
return floor($timeDiff / 31536000) . '年前';
}
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Model;
class CertTag extends Model
{
}
\ No newline at end of file
......@@ -37,23 +37,22 @@ class Course extends Model
}
/**获取分类下的课程列表
* @param $cate_id
* @return Course[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*
*/
public function getCourseList($cate_id = 0)
public function getCourseList($category_id,$page,$pageSize)
{
$where = ['status'=>3,'is_sell'=>1,'is_del'=>0];
if ($cate_id)
if ($category_id)
{
$where['cate_id'] = $cate_id;
$where['cate_id'] = $category_id;
}
return self::where($where)
->field('id,thumb,title,createtime,description,price,content')
->select();
->paginate([
'page' => $page,
'list_rows' => $pageSize
]);
}
//获取课程详情
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment