| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\api\model;
- use app\common\model\SpecialityBook as SpecialityBookModel;
- /**
- * 学校专业模型类
- * Class SpecialityBook
- * @package app\api\model
- */
- class SpecialityBook extends SpecialityBookModel
- {
- protected $globalScope = [''];
- /**
- * 隐藏字段
- * @var array
- */
- protected $hidden = [
- 'update_time'
- ];
- /**
- * 获取列表
- * @param array $param 查询条件
- * @param int $listRows 分页数量
- * @return mixed|\think\model\Collection|\think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function getList(array $param = [], int $listRows = 12)
- {
- // 整理查询参数
- $params = array_merge($param);
- // 获取商品列表
- $list = parent::getList($params, $listRows);
- if ($list->isEmpty()) {
- return $list;
- }
- // 整理列表数据并返回
- return $this->setListDataFromApi($list);
- }
- /**
- * 设置展示的数据 api模块
- * @param $info
- * @return mixed
- */
- private function setListDataFromApi($info)
- {
- return $this->setListData($info, function ($data){
- // 整理数据 api模块
- $this->setDataFromApi($data);
- // 隐藏冗余的字段
- $this->hidden(array_merge($this->hidden, ['transaction_id']));
- });
- }
- /**
- * 整理数据 api模块
- * @param $info
- * @return mixed
- */
- private function setDataFromApi($info)
- {
- return $this->setData($info, function ($data) {
- });
- }
- /**
- * 获取学校的专业
- * @param int $school_id 学校ID
- * @param string $field 返回字段
- * @param int $limit 返回数量
- * @return SpecialityBook[]|array|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getBooks(int $speciality_id)
- {
- return self::where(['speciality_id'=>$speciality_id])->where('status','>', 2)->count('order_id');
- }
- /**
- * 获取用户已经报名次数
- * @param int $userId
- * @param int $specialityId
- * @return int
- */
- public static function getUserBooks(int $userId, $specialityId=0)
- {
- $where = ['book_user_id'=> $userId];
- if($specialityId){
- $where['speciality_id'] = $specialityId;
- }
- return self::where($where)->where('status','>', 2)->count('order_id');
- }
- /**
- * 计算咨询老师的报名订单数量
- * @param $userId 老师用户ID
- * @param int $status 状态:1-包含待支付,2-已支付
- * @return int
- */
- public static function getBooksByTeacher($userId, $status = 2)
- {
- $where = ['user_id'=> $userId];
- $status = $status == 1? 1 : 3;
- return (int)self::where($where)->where('status','>=', $status)->count('order_id');
- }
- /**
- * 统计今日新增报名数
- * @param int $status 状态:1-包含待支付,2-已支付
- * @param $schoolId
- * @return int
- */
- public static function getBooksByToday(int $status = 3, $schoolId=0)
- {
- $status = $status == 1? 1 : 3;
- return (int)self::where('status','>=', $status)
- ->where(function($query) use($schoolId){
- if($schoolId>0){
- $query->where('school_id', $schoolId);
- }
- })
- ->where('create_time','>=', strtotime(date('Y-m-d')))
- ->count('order_id');
- }
- }
|