AnnounceModel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Models\Mysql;
  3. use App\Models\Mongo\AgentAttrsLogsModel;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\DB;
  6. class AnnounceModel extends BaseMysql
  7. {
  8. /**
  9. * 表名
  10. * @var string
  11. */
  12. protected $table = 'announce';
  13. /**
  14. * UUID 键名
  15. * @var string
  16. */
  17. protected $uuidKeyName = 'uid';
  18. /**
  19. * The "booted" method of the model.
  20. *
  21. * @return void
  22. */
  23. protected static function boot()
  24. {
  25. parent::boot();
  26. self::creating(function ($model) {
  27. $model->{$model->uuidKeyName} = self::generateId($model->uuidKeyName);
  28. });
  29. self::created(function ($model) {
  30. $uuid = hashEncodeId($model->id);
  31. $model->{$model->uuidKeyName} = $uuid;
  32. $model->save();
  33. });
  34. }
  35. /**
  36. * 关联1个应用.
  37. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  38. */
  39. public function app()
  40. {
  41. return $this->hasOne(AppModel::class, 'uid', 'mom_app_uid');
  42. }
  43. /**
  44. * 关联一个代理
  45. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  46. */
  47. public function agent()
  48. {
  49. return $this->belongsTo(AgentModel::class, 'uid', 'agent_uid');
  50. }
  51. }