12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?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(['nickname_remark' => $remark, 'updatetime' => time()]);
- } else {
- $res = $this->insert(['user_id' => $user_id, 'to_user_id' => $to_user_id, 'nickname_remark' => $remark, 'updatetime' => 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(['nickname_remark' => '', 'updatetime' => time()]);
- if (!$res) {
- return [false, '设置失败'];
- }
- }
- return [true, '设置成功'];
- }
- }
|