123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Http\Controllers\AdminApi;
- use App\Models\MessageModels\Message;
- use App\Http\Controllers\AdminController;
- class MessageController extends AdminController
- {
- /**
- * 获取留言列表
- * @return \Illuminate\Http\JsonResponse
- */
- function getList(){
- $name = request()->input('name','');//获取搜索名称
- $phone = request()->input('phone','');//获取搜索手机号
- $start = request()->input('start','');//获取开始时间
- $end = request()->input('end','');//获取结束时间
- //查询数据条件
- $where = [['is_del',0]];
- if ($name) $where[] = ['name', 'like', "%$name%"];
- if ($phone) $where[] = ['phone', 'like', "%$phone%"];
- if ($start) $where[] = ['created_at', '>=', $start];
- if ($end) $where[] = ['created_at', '<=', $end];
- //获取数据
- $list = Message::where($where)
- ->orderBy('id','desc')
- ->select(['id','name','phone','created_at'])
- ->paginate(10);
- return $this->apiResponseSuccess('获取信息成功', [
- 'list' => $list->items(),
- 'total' => $list->total(),
- 'limit' => 10
- ]);
- }
- /**
- * 获取记录详情
- * @return \Illuminate\Http\JsonResponse
- */
- function getInfo()
- {
- $id = request()->input('id', '');//获取需要查询的记录id
- if (empty($id)) return $this->apiResponseError('缺少必要参数');
- //查询数据
- $where = [['id', $id], ['is_del',0]];
- $info = Message::where($where)->select(['id', 'name', 'phone', 'content', 'created_at'])->first();
- if (empty($info)) return $this->apiResponseError('没有找到该记录');
- return $this->apiResponseSuccess('获取成功', $info);
- }
- /**
- * 删除(批量)记录
- * @return \Illuminate\Http\JsonResponse
- */
- function destroys(){
- $ids = request()->input('ids','');//获取需要删除的id
- if(empty($ids)) return $this->apiResponseError('缺少必要参数');
- //数据条件
- if(!is_array($ids)) return $this->apiResponseError('数据格式错误');
- $res = Message::whereIn('id',$ids)->update(['is_del' => 1]);
- if ($res) {
- return $this->apiResponseSuccess('删除成功');
- } else {
- return $this->apiResponseError('删除失败');
- }
- }
- }
|