StoreServiceLog.php 2.5 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 StoreServiceLog
  19. * @package app\model\service
  20. */
  21. class StoreServiceLog extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'store_service_log';
  34. public function getAddTimeAttr($value)
  35. {
  36. return $value ? date('Y-m-d H:i:s', $value) : '';
  37. }
  38. /**
  39. * 一对一关联
  40. * @return mixed
  41. */
  42. public function service()
  43. {
  44. return $this->hasOne(StoreService::class, 'uid', 'uid')->field(['uid', 'nickname', 'avatar'])->bind([
  45. 'nickname' => 'nickname',
  46. 'avatar' => 'avatar'
  47. ]);
  48. }
  49. /**
  50. * 一对一关联
  51. * @return mixed
  52. */
  53. public function user()
  54. {
  55. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname', 'avatar'])->bind([
  56. 'nickname' => 'nickname',
  57. 'avatar' => 'avatar'
  58. ]);
  59. }
  60. /**
  61. * uid搜索器
  62. * @param Model $query
  63. * @param $value
  64. */
  65. public function searchUidAttr($query, $value)
  66. {
  67. $query->where('uid|to_uid', $value);
  68. }
  69. /**
  70. * 聊天记录搜索器
  71. * @param Model $query
  72. * @param $value
  73. */
  74. public function searchChatAttr($query, $value)
  75. {
  76. $query->whereIn('uid', $value)->whereIn('to_uid', $value);
  77. }
  78. /**
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchTypeAttr($query, $value)
  83. {
  84. $query->where('type', $value);
  85. }
  86. /**
  87. * @param Model $query
  88. * @param $value
  89. */
  90. public function searchIsTouristAttr($query, $value)
  91. {
  92. $query->where('is_tourist', $value);
  93. }
  94. }