DriverMessageReadModel.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model\Arts;
  4. use App\Master\Enum\RedisKeyEnum;
  5. use App\Model\Model;
  6. use App\Utils\RedisUtil;
  7. use Hyperf\DbConnection\Db;
  8. class DriverMessageReadModel extends Model
  9. {
  10. /**
  11. * The table associated with the model.
  12. *
  13. * @var ?string
  14. */
  15. protected ?string $table = 'driver_message_read';
  16. protected ?string $dateFormat = 'U';
  17. public bool $timestamps = false;
  18. protected int $is_status_search = 0;// 是否使用 1=是 0=否 默认使用 status = 1 筛选
  19. protected int $is_delete_search = 0;// 是否使用 1=是 0=否 默认使用 is_delete = 0 筛选
  20. /**
  21. * 默认查询字段
  22. *
  23. * @var array|string[]
  24. */
  25. public array $select = [
  26. '*'
  27. ];
  28. public function searchDriverIdAttribute($query, $value, array $params): mixed
  29. {
  30. if (empty($value)) {
  31. return $query;
  32. }
  33. return $query->where('driver_id', $value);
  34. }
  35. public function searchIsReadAttribute($query, $value, array $params): mixed
  36. {
  37. if (empty($value)) {
  38. return $query;
  39. }
  40. return $query->where('is_read', $value);
  41. }
  42. public function searchIdAttribute($query, $value, array $params): mixed
  43. {
  44. if (empty($value)) {
  45. return $query;
  46. }
  47. return $query->where('id', $value);
  48. }
  49. public static function add(array $params)
  50. {
  51. $insert = array_merge($params,[
  52. 'status' => 1,
  53. 'create_time' => time()
  54. ]);
  55. return self::query()->insertGetId($insert);
  56. }
  57. public static function edit(int $id, array $params)
  58. {
  59. unset($params['id']);
  60. $insert = array_merge($params,[
  61. 'update_time' => time()
  62. ]);
  63. $query = self::query()->where('id',$id);
  64. return $query->update($insert);
  65. }
  66. }