From d7046959aad56cd7f7f09ac9f5cc89e50b324712 Mon Sep 17 00:00:00 2001 From: xman <1946321327@qq.com> Date: Mon, 21 Apr 2025 11:59:42 +0800 Subject: [PATCH] sth --- application/admin/controller/Message.php | 134 ++++++++++++++++++ .../admin/controller/orders/Auditorder.php | 8 ++ application/admin/lang/zh-cn/message.php | 15 ++ application/admin/model/Message.php | 86 +++++++++++ application/admin/validate/Message.php | 27 ++++ application/admin/view/common/header.html | 16 ++- application/admin/view/message/add.html | 69 +++++++++ application/admin/view/message/edit.html | 69 +++++++++ application/admin/view/message/index.html | 26 ++++ public/assets/js/addons.js | 4 +- public/assets/js/backend/message.js | 62 ++++++++ 11 files changed, 512 insertions(+), 4 deletions(-) create mode 100644 application/admin/controller/Message.php create mode 100644 application/admin/lang/zh-cn/message.php create mode 100644 application/admin/model/Message.php create mode 100644 application/admin/validate/Message.php create mode 100644 application/admin/view/message/add.html create mode 100644 application/admin/view/message/edit.html create mode 100644 application/admin/view/message/index.html create mode 100644 public/assets/js/backend/message.js diff --git a/application/admin/controller/Message.php b/application/admin/controller/Message.php new file mode 100644 index 0000000..c769785 --- /dev/null +++ b/application/admin/controller/Message.php @@ -0,0 +1,134 @@ +model = new \app\admin\model\Message; + $this->view->assign("typeList", $this->model->getTypeList()); + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + + /** + * 查看 + * + * @return string|Json + * @throws \think\Exception + * @throws DbException + */ + public function index() + { + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->where('type',1) + ->auth($this->auth) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + + $update = []; + foreach ($list as $item){ + $readUids = explode(',',$item->read_uid); + if(!in_array($this->auth->id,$readUids)){ + $readUids[] = $this->auth->id; + $update[] = [ + 'id' => $item->id, + 'read_uid' => implode(',',$readUids) + ]; + } + } + if($update){ + $this->batchUpdateByIdSimple('fa_message',$update); + } + return json($result); + } + + + /** + * 通用批量更新方法(自动识别主键和字段,无循环) + * + * @param string $table 表名 + * @param array $data 数据数组,格式如 [['id' => 1, 'field1' => 'v1'], ['id' => 2, 'field1' => 'v2']] + * @param string $idField 主键字段名,默认 'id' + * @return int 更新影响行数 + */ + protected function batchUpdateByIdSimple(string $table, array $data, string $idField = 'id'): int + { + if (empty($data)) return 0; + + $ids = array_column($data, $idField); + $fields = array_keys(array_diff_key($data[0], [$idField => ''])); + + $sqlParts = []; + foreach ($fields as $field) { + $case = "CASE {$idField}"; + foreach ($data as $row) { + $id = intval($row[$idField]); + $val = addslashes($row[$field]); + $case .= " WHEN {$id} THEN '{$val}'"; + } + $case .= " END"; + $sqlParts[] = "{$field} = {$case}"; + } + + $sql = sprintf( + "UPDATE %s SET %s WHERE %s IN (%s)", + $table, + implode(", ", $sqlParts), + $idField, + implode(',', array_map('intval', $ids)) + ); + + return Db::execute($sql); + } + + + public function getNoreadCount() + { + return $this->model + ->where('type',1) + ->auth($this->auth) + ->whereRaw("FIND_IN_SET(?, read_uid) = 0 OR read_uid IS NULL OR read_uid = ''", [$this->auth->id]) + ->count(); + } + +} diff --git a/application/admin/controller/orders/Auditorder.php b/application/admin/controller/orders/Auditorder.php index 5e396b0..8e1118c 100644 --- a/application/admin/controller/orders/Auditorder.php +++ b/application/admin/controller/orders/Auditorder.php @@ -2,6 +2,7 @@ namespace app\admin\controller\orders; +use app\admin\model\Message; use app\admin\model\Order; use app\common\controller\Backend; use think\Db; @@ -143,6 +144,13 @@ class Auditorder extends Backend $hookParams['remark'] = $params['audit_remark']; Hook::listen('order_change',$hookParams); + //未通过审核,通知派单员,重新配置 + Message::create([ + 'to_id' => $row->dispatch_admin_id, + 'type' => 1, + 'title' => '订单'.$row->order_no.'财务审核未通过,请重新配置', + 'content' => '订单编号:'.$row->order_no.',审核说明:'.$params['audit_remark'].',审核人:'.$this->auth->nickname + ]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); diff --git a/application/admin/lang/zh-cn/message.php b/application/admin/lang/zh-cn/message.php new file mode 100644 index 0000000..0ccd1ad --- /dev/null +++ b/application/admin/lang/zh-cn/message.php @@ -0,0 +1,15 @@ + '接收人', + 'Area_id' => '接收地址', + 'Type' => '类型', + 'Type 1' => '系统消息', + 'Type 2' => '师傅消息', + 'Title' => '标题', + 'Read_uid' => '已读用户', + 'Content' => '内容', + 'Uri' => '带参相对地址', + 'Create_time' => '创建时间', + 'Update_time' => '更新时间' +]; diff --git a/application/admin/model/Message.php b/application/admin/model/Message.php new file mode 100644 index 0000000..aa8c3d8 --- /dev/null +++ b/application/admin/model/Message.php @@ -0,0 +1,86 @@ + __('Type 1'), '2' => __('Type 2')]; + } + + + public function getTypeTextAttr($value, $data) + { + $value = $value ?: ($data['type'] ?? ''); + $list = $this->getTypeList(); + return $list[$value] ?? ''; + } + + + + /** + * 管理员权限 + * @param $query + * @param Auth $auth + * @param string $auth_admin_id + * @return mixed + */ + public function scopeAuth($query, Auth $auth, string $admin_id_field='to_id'){ + + if(!$auth->isSuperAdmin()){ + $query->where($admin_id_field,$auth->id); + } + return $query; + } + + + + + /** + * 地域权限 + * @param $query + * @param Auth $auth + * @param string $area_id_field + * @return mixed + */ + public function scopeAreaauth($query,Auth $auth,string $area_id_field='area_id'){ + if(!$auth->isSuperAdmin()){ + $areaIds = array_unique(array_filter(explode(',',trim($auth->area_ids)))); + if(!in_array('*',$areaIds)){ + $query->whereIn($area_id_field,$areaIds); + } + } + return $query; + } + +} diff --git a/application/admin/validate/Message.php b/application/admin/validate/Message.php new file mode 100644 index 0000000..b37b194 --- /dev/null +++ b/application/admin/validate/Message.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/common/header.html b/application/admin/view/common/header.html index 5344058..471cce4 100755 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -25,7 +25,10 @@