60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use app\common\library\DatabaseRoute;
|
|
use app\common\model\BaseModel;
|
|
use app\common\model\Common;
|
|
use app\common\model\SysUser;
|
|
use ba\Exception;
|
|
use app\exception\SysException;
|
|
use ba\Random;
|
|
use think\facade\Db;
|
|
use think\Model;
|
|
|
|
class MessageInfo extends Model
|
|
{
|
|
public static function getList($data)
|
|
{
|
|
if(empty($data['page']) || empty($data['state']) || empty($data['limit'])) {
|
|
return returnErrorData('参数不完整');
|
|
}
|
|
$page = ($data['page'] - 1) * $data['limit'];
|
|
$db = Db::connect(config('think-orm.search_library'))->name('message_info');
|
|
if(!empty($data['user_id'])) {
|
|
$where = [
|
|
'state' => $data['state'],
|
|
'user_id' => $data['user_id'],
|
|
];
|
|
}else {
|
|
$where = [
|
|
'state' => $data['state'],
|
|
];
|
|
}
|
|
$list = $db->where($where)->limit($page, $data['limit'])->select()->toArray();
|
|
$list = convertToCamelCase($list);
|
|
$count = $db->where($where)->count();
|
|
$return = [
|
|
'currPage' => 1,
|
|
'list' => $list,
|
|
'pageSize' => $data['limit'],
|
|
'totalCount' => $count,
|
|
'totalPage' => ceil($count / $data['limit']),
|
|
];
|
|
return returnSuccessData($return);
|
|
}
|
|
|
|
|
|
|
|
public static function sendMessage($data, $user_id)
|
|
{
|
|
if(empty($data['content']) || empty($data['state']) || empty($data['title'])) {
|
|
return returnErrorData('参数不完整');
|
|
}
|
|
$data['user_id'] = $user_id;
|
|
$data['create_at'] = date('Y-m-d H:i:s');
|
|
MessageInfo::create($data);
|
|
return returnSuccessData();
|
|
}
|
|
|
|
} |