add
This commit is contained in:
60
app/api/model/MessageInfo.php
Normal file
60
app/api/model/MessageInfo.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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('database.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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user