Quellcode durchsuchen

[智价云] 小程序站内信

tangyuanwang vor 11 Stunden
Ursprung
Commit
7b68952262

+ 133 - 0
app/Http/Controllers/Api/Process/Notice.php

@@ -0,0 +1,133 @@
+<?php
+
+namespace App\Http\Controllers\Api\Process;
+
+use App\Http\Controllers\Api\Api;
+use App\Http\Requests\Api\Process\Notices as Request;
+use App\Models\Api\Process\Notices as NoticesModel;
+
+/**
+ * 通知服务
+ * @author: 唐远望
+ * @version: 1.0
+ * @date: 2026-03-30
+ */
+class Notice extends Api
+{
+    /**
+     * 列表
+     * @author: 唐远望
+     * @version: 1.0
+     * @date: 2026-03-30
+     */
+    public function list(Request $Request, NoticesModel $NoticesModel)
+    {
+        $user_info = $this->checkLogin();
+        if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
+        $user_id = $user_info['uid'];
+        // 验证规则
+        $Request->scene('list')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $map = [];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map['company_id'] = $company_id;
+            $map['custom_uid'] = $user_id;
+        } else {
+            $map['company_id'] = $admin_company_id;
+        }
+        // 接收参数
+        $status                        = request('status');
+        $limit                        = request('limit', config('page_num', 10));
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+
+        // 时间条件
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time . ' 00:00:00')];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time . ' 23:59:59')];
+        if (!is_null($status))        $map[] = ['status', '=', $status];
+        // 查询系统用户
+        $result                    = $NoticesModel->where($map)->orderByDesc('id')->paginate($limit);
+        // 告知结果
+        return                        json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+
+    /**
+     * 修改状态
+     * @author: 唐远望
+     * @version: 1.0
+     * @date: 2026-03-30
+     */
+    public function set_status(Request $request, NoticesModel $NoticesModel)
+    {
+        $user_info = $this->checkLogin();
+        if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
+        $user_id = $user_info['uid'];
+        // 验证参数
+        $request->scene('set_status')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $map = [];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map['company_id'] = $company_id;
+            $map['custom_uid'] = $user_id;
+        } else {
+            $map['company_id'] = $admin_company_id;
+        }
+        // 设置状态
+        $id                                = request('id', 0);
+        $status                            = request('status', 0);
+        $map[]                             = ['id', '=', $id];
+        // 查询用户
+        $oldData                        = $NoticesModel->where($map)->first();
+        // 如果用户不存在
+        if (!$oldData)                    return json_send(['code' => 'error', 'msg' => '通知消息记录不存在']);
+        // 执行修改
+        $result                            = $NoticesModel->where($map)->update(['status' => $status, 'update_time' => time()]);
+        // 提示新增失败
+        if (!$result)                    return json_send(['code' => 'error', 'msg' => '设置失败']);
+        // 记录行为
+        $admin_id   = request('access_token.uid', 0); //用户ID
+        $table_name = $NoticesModel->getTable();
+        $notes_type = 2; //操作类型,1添加,2修改,3=删除
+        $this->addAdminHistory('系统通知', 0, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], "修改了记录ID为:$id 的通知状态");
+        // 告知结果
+        return                          json_send(['code' => 'success', 'msg' => '设置成功', 'data' => '']);
+    }
+
+    /**
+     * 消息数统计
+     * @author: 唐远望
+     * @version: 1.0
+     * @date: 2026-03-30
+     */
+    public function message_count(Request $Request, NoticesModel $NoticesModel)
+    {
+        $user_info = $this->checkLogin();
+        if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
+        $user_id = $user_info['uid'];
+        // 验证规则
+        $Request->scene('message_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $map = [];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map['company_id'] = $company_id;
+            $map['custom_uid'] = $user_id;
+        } else {
+            $map['company_id'] = $admin_company_id;
+        }
+        $map[] = ['status', '=', 0];
+        // 查询系统用户
+        $unread_count                    = $NoticesModel->where($map)->orderByDesc('id')->count();
+        // 告知结果
+        return                        json_send(['code' => 'success', 'msg' => '获取成功', 'data' => ['unread_count' => $unread_count]]);
+    }
+}

+ 70 - 0
app/Http/Requests/Api/Process/Notices.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace App\Http\Requests\Api\Process;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 通知处理请求类
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-03-30
+ * 
+ */
+class Notices extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            'name'                 => 'required',
+            'id'                => 'required|integer|gt:0',
+            'status'            => 'required|integer|in:0,1',
+            'page'              => 'integer|min:1',
+            'limit'             => 'integer|min:1',
+            'status'            => 'required|integer|in:0,1',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => [],
+        'edit'                      => [],
+        'set_status'              => ['id', 'status'],
+        'set_processing_status'   => ['id'],
+        'delete'                  => ['id'],
+        'data_cleaning'           => [''],
+        'export_excel'            => [''],
+        'message_count'            => ['']
+    ];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'name.required'     => '名称必填',
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'               => 'ID格式错误',
+            'status.required'   => '状态未知',
+            'status.integer'    => '状态格式错误',
+            'status.in'         => '状态格式错误',
+            'page.integer'      => '页码格式错误',
+            'page.min'          => '页码格式错误',
+            'limit.integer'     => '每页数量格式错误',
+            'limit.min'         => '每页数量格式错误',
+        ];
+    }
+}

+ 135 - 0
app/Models/Api/Process/Notices.php

@@ -0,0 +1,135 @@
+<?php
+
+namespace App\Models\Api\Process;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 通知消息模型
+ * @author: 唐远望
+ * @version: 1.0
+ * @date: 2026-03-30
+ */
+class Notices extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'process_notices';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-03-30
+     */
+    public function addNotices_content($data)
+    {
+        $insert_data = [
+            'title' => $data['title'],
+            'content' => $data['content'],
+            'msg_type'    => $data['msg_type'],
+            'custom_uid' => $data['custom_uid'],
+        ];
+        $Notices_id = $this->insertGetId($insert_data);
+        return $Notices_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-03-30
+     * @param $data
+     * @return bool
+     */
+    public function addNotices($data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->addNotices_content($data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-03-30
+     * @param $data
+     * @return bool
+     */
+    public function editNotices_content($where, $data)
+    {
+        $Notices = $this->where($where)->first();
+        if (!$Notices) {
+            return false;
+        }
+        $Notices->title = $data['title'];
+        $Notices->content = $data['content'];
+        $Notices->msg_type = $data['msg_type'];
+        $Notices->custom_uid = $data['custom_uid'];
+        $Notices->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-03-30
+     * @param $data
+     * @return bool
+     */
+    public function updateNotices($where, $data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->editNotices_content($where, $data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2026-03-30
+     * @param $id
+     * @return bool
+     */
+    public function deleteNotices($where)
+    {
+        $Notices = $this->where($where)->first();
+        if (!$Notices) {
+            return false;
+        }
+        $Notices->delete();
+        return true;
+    }
+}

+ 8 - 1
routes/api.php

@@ -92,4 +92,11 @@ Route::any('personnel/subscribe/change_subscribe', [App\Http\Controllers\Api\Per
 // 潜在客户留言-新增
 Route::any('website/lead_message/add', [App\Http\Controllers\Api\Website\LeadMessage::class, 'add']);
 // 潜在客户留言-发送验证码
-Route::any('website/lead_message/send_code', [App\Http\Controllers\Api\Website\LeadMessage::class, 'send_code']);
+Route::any('website/lead_message/send_code', [App\Http\Controllers\Api\Website\LeadMessage::class, 'send_code']);
+
+//违规处理-通知列表
+Route::any('process/notice/list', [App\Http\Controllers\Api\Process\Notice::class, 'list']);
+//违规处理-通知修改状态
+Route::any('process/notice/set_status', [App\Http\Controllers\Api\Process\Notice::class, 'set_status']);
+//违规处理-消息数统计
+Route::any('process/notice/message_count', [App\Http\Controllers\Api\Process\Notice::class, 'message_count']);