|
@@ -0,0 +1,64 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace app\common\model;
|
|
|
|
+
|
|
|
|
+use think\Model;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 系统消息模型
|
|
|
|
+ */
|
|
|
|
+class UserRemark extends Model
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ // 表名
|
|
|
|
+ protected $name = 'user_remark';
|
|
|
|
+
|
|
|
|
+ // 自动写入时间戳字段
|
|
|
|
+ protected $autoWriteTimestamp = false;
|
|
|
|
+
|
|
|
|
+ // 定义时间戳字段名
|
|
|
|
+ protected $createTime = false;
|
|
|
|
+ protected $updateTime = false;
|
|
|
|
+ protected $deleteTime = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置备注
|
|
|
|
+ * @param int $user_id
|
|
|
|
+ * @param int $to_user_id
|
|
|
|
+ * @param string $remark
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function setRemark(int $user_id, int $to_user_id, string $remark = '')
|
|
|
|
+ {
|
|
|
|
+ if ($user_id === $to_user_id) {
|
|
|
|
+ return [false, '不可以给自己设置备注'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($info = $this->where(['user_id' => $user_id, 'to_user_id' => $to_user_id])->find()) {
|
|
|
|
+ $res = $this->where('id', $info['id'])->update(['remark' => $remark, 'updated_time' => time()]);
|
|
|
|
+ } else {
|
|
|
|
+ $res = $this->insert(['user_id' => $user_id, 'to_user_id' => $to_user_id, 'remark' => $remark, 'updated_time' => time()]);
|
|
|
|
+ }
|
|
|
|
+ if (!$res) {
|
|
|
|
+ return [false, '设置失败'];
|
|
|
|
+ }
|
|
|
|
+ return [true, '设置成功'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除备注
|
|
|
|
+ * @param int $user_id
|
|
|
|
+ * @param int $to_user_id
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function delRemark(int $user_id, int $to_user_id)
|
|
|
|
+ {
|
|
|
|
+ if ($info = $this->where(['user_id' => $user_id, 'to_user_id' => $to_user_id])->find()) {
|
|
|
|
+ $res = $this->where('id', $info['id'])->update(['remark' => '', 'updated_time' => time()]);
|
|
|
|
+ if (!$res) {
|
|
|
|
+ return [false, '设置失败'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return [true, '设置成功'];
|
|
|
|
+ }
|
|
|
|
+}
|