MedicalSalesman.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\model;
  3. use support\Model;
  4. class MedicalSalesman extends Model
  5. {
  6. protected $table = 'medical_salesman';
  7. protected $primaryKey = 'salesman_id';
  8. protected $dateFormat = 'U';
  9. public const CREATED_AT = 'salesman_addTime';
  10. public const UPDATED_AT = 'salesman_updateTime';
  11. public function serializeDate(\DateTimeInterface $date)
  12. {
  13. return $date->format('Y-m-d H:i:s');
  14. }
  15. public function shop()
  16. {
  17. return $this->hasOne(MedicalShop::class,'shop_id','salesman_shop_id');
  18. }
  19. /**
  20. * @Desc 手机号是否已存在
  21. * @Author Gorden
  22. * @Date 2024/3/4 9:46
  23. *
  24. * @param $phone
  25. * @return bool
  26. */
  27. public function phoneExist($phone)
  28. {
  29. return self::where('salesman_phone', $phone)->exists();
  30. }
  31. /**
  32. * @Desc 用户名是否存在
  33. * @Author Gorden
  34. * @Date 2024/3/4 10:08
  35. *
  36. * @param $username
  37. * @return bool
  38. */
  39. public function usernameExist($username)
  40. {
  41. return self::where('salesman_username', $username)->exists();
  42. }
  43. /**
  44. * @Desc 更新时,验证手机号是否在其他账号下出现
  45. * @Author Gorden
  46. * @Date 2024/3/4 10:14
  47. *
  48. * @param $phone
  49. * @param $id
  50. * @return bool
  51. */
  52. public function phoneIsInOtherAccountExist($phone, $id)
  53. {
  54. return self::where('salesman_phone', $phone)
  55. ->where('salesman_id', '<>', $id)
  56. ->exists();
  57. }
  58. /**
  59. * @Desc 更新时,验证用户名是否在其他账号下出现
  60. * @Author Gorden
  61. * @Date 2024/3/4 10:16
  62. *
  63. * @param $username
  64. * @param $id
  65. * @return bool
  66. */
  67. public function usernameIsInOtherAccountExist($username, $id)
  68. {
  69. return self::where('salesman_username', $username)
  70. ->where('salesman_id', '<>', $id)
  71. ->exists();
  72. }
  73. }