Files
CompanyProject/芳林公司项目/www.zhiyuanhelp.com/application/admin/model/costom/Message.php
2024-09-27 01:32:49 +08:00

107 lines
3.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/4/24
* Time: 15:06
*/
namespace app\admin\model\costom;
use think\Model;
class Message extends Model
{
protected $table = 'user_message';
/**
* 获取留言建议列表信息
* @param int $page 当前页
* @param int $limit 每页显示数量
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function messageList($page = 1, $limit = 10, $search = []){
$where = [];
//搜索条件
foreach ($search as $key => $value) {
if (!empty($value)) {
switch ($key) {
case 'add_time':
$value_list = explode(" - ", $value);
$value_list[0] = strtotime($value_list[0]);
$value_list[1] = strtotime($value_list[1]);
$where[] = [$key, 'BETWEEN', ["$value_list[0]", "$value_list[1]"]];
break;
case 'status':
$where[] = [$key, '=', $value];
break;
case 'telnum':
$where[] = [$key, '=', $value];
break;
case 'type':
$where[] = [$key, '=', $value-1];
break;
default:
!empty($value) && $where[] = [$key, 'LIKE', '%' . $value . '%'];
}
}
}
$count = self::where($where)->count();
$data = self::where($where)->page($page, $limit)->order([ 'add_time' => 'desc'])->select();
empty($data) ? $msg = '暂无数据!' : $msg = '查询成功!';
foreach ($data as $key => $val){
$val['add_time'] = date('Y-m-d H:i:s',$val['add_time']);
if($val['reply_time']){
$val['reply_time'] = date('Y-m-d H:i:s',$val['reply_time']);
}
$val['img1'] = config('secure.mpic_url'). $val['img1'];
$val['img2'] = config('secure.mpic_url'). $val['img2'];
if($val['type']){
$val['type'] = config('setmes.mesName')[$val['type']];
}else{
$val['type'] = '考生建议';
}
}
$info = [
'limit' => $limit,
'page_current' => $page,
'page_sum' => ceil($count / $limit),
];
$list = [
'code' => 0,
'msg' => $msg,
'count' => $count,
'info' => $info,
'data' => $data,
];
return $list;
}
/*
* 回复问题
* */
public function reply($post){
$post['reply'] = $post['replyCon'];
$post['status'] = 2;
unset($post['replyCon']);
try {
self::where('id', $post['id'])->update($post);
} catch (\Exception $e) {
return __error($e->getMessage());
}
return __success('回复成功');
}
}