|
@@ -0,0 +1,78 @@
|
|
|
+<?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', '');
|
|
|
+ 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','');
|
|
|
+ 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('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|