yijia-webman/app/model/ReadingBook.php

36 lines
929 B
PHP

<?php
namespace app\model;
class ReadingBook extends Base
{
protected $table = 'reading_book';
protected $autoWriteTimestamp = false;
//阶段
protected static $status = [
'to-read' => '待阅读',
'reading' => '阅读中',
'finished' => '已阅读'
];
public static function getList($readingID)
{
$list = self::alias('rb')
->leftJoin('book b', 'rb.book_id = b.id')
->leftJoin('category c', 'b.category_id = c.id')
->field('rb.*,b.name as book_name,b.author,c.name as category_name')
->where('rb.reading_id', $readingID)
->order('rb.sort', 'asc')
->select();
return $list->each(function($item){
$item->statusStr = self::$status[$item['status']];
});
}
public static function onAfterInsert($model)
{
$model->sort = $model->id;
$model->save();
}
}