StoreServiceRecord.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\service;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 客服聊天用户记录
  18. * Class StoreServiceRecord
  19. * @package app\model\service
  20. */
  21. class StoreServiceRecord extends BaseModel
  22. {
  23. use ModelTrait;
  24. protected $name = 'store_service_record';
  25. protected $pk = 'id';
  26. /**
  27. * 更新时间
  28. * @var bool | string | int
  29. */
  30. protected $updateTime = false;
  31. /**
  32. * 用户关联
  33. * @return \think\model\relation\HasOne
  34. */
  35. public function user()
  36. {
  37. return $this->hasOne(User::class, 'uid', 'to_uid')->field(['nickname', 'uid', 'avatar'])->bind([
  38. 'wx_nickname' => 'nickname',
  39. 'wx_avatar' => 'avatar',
  40. ]);
  41. }
  42. /**
  43. * 客服用户
  44. * @return \think\model\relation\HasOne
  45. */
  46. public function service()
  47. {
  48. return $this->hasOne(StoreService::class, 'uid', 'to_uid')->field(['nickname', 'uid', 'avatar'])->bind([
  49. 'kefu_nickname' => 'nickname',
  50. 'kefu_avatar' => 'avatar',
  51. ]);
  52. }
  53. /**
  54. * 发送者id搜索器
  55. * @param Model $query
  56. * @param $value
  57. */
  58. public function searchUserIdAttr($query, $value)
  59. {
  60. $query->where('user_id', $value);
  61. }
  62. /**
  63. * 送达人uid搜索器
  64. * @param Model $query
  65. * @param $value
  66. */
  67. public function searchToUidAttr($query, $value)
  68. {
  69. $query->where('to_uid', $value);
  70. }
  71. /**
  72. * 用户昵称搜索器
  73. * @param Model $query
  74. * @param $value
  75. */
  76. public function searchTitleAttr($query, $value)
  77. {
  78. if ($value) {
  79. $query->whereIn('to_uid', function ($query) use ($value) {
  80. $query->name('user')->whereLike('nickname|uid', '%' . $value . '%')->field('uid');
  81. });
  82. }
  83. }
  84. /**
  85. * 是否游客
  86. * @param Model $query
  87. * @param $value
  88. */
  89. public function searchIsTouristAttr($query, $value)
  90. {
  91. $query->where('is_tourist', $value);
  92. }
  93. }