CustomerServiceUser.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\model\shopro\chat;
  3. use app\admin\model\Admin;
  4. use app\admin\model\shopro\Common;
  5. use app\admin\model\shopro\chat\CustomerService;
  6. use app\admin\model\shopro\user\User as ShopUser;
  7. class CustomerServiceUser extends Common
  8. {
  9. protected $name = 'shopro_chat_customer_service_user';
  10. protected $append = [
  11. 'auth_model',
  12. 'auth_text'
  13. ];
  14. public static $authType = [
  15. 'admin' => ['name' => '管理员', 'value' => 'admin'],
  16. 'user' => ['name' => '用户', 'value' => 'user'],
  17. ];
  18. public function scopeAuthAdmin($query, $admin_id)
  19. {
  20. return $query->where('auth', 'admin')->where('auth_id', $admin_id);
  21. }
  22. public function scopeAuthUser($query, $user_id)
  23. {
  24. return $query->where('auth', 'user')->where('auth_id', $user_id);
  25. }
  26. public function getAuthModelAttr($value, $data)
  27. {
  28. return $this->{$data['auth']};
  29. }
  30. public function getAuthTextAttr($value, $data)
  31. {
  32. return self::$authType[$data['auth']]['name'] ?? '';
  33. }
  34. public function admin()
  35. {
  36. return $this->belongsTo(Admin::class, 'auth_id');
  37. }
  38. public function customerService()
  39. {
  40. return $this->belongsTo(CustomerService::class, 'customer_service_id');
  41. }
  42. public function user()
  43. {
  44. return $this->belongsTo(ShopUser::class, 'auth_id');
  45. }
  46. }