ChannelModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 ChannelModel extends BaseMysql
  7. {
  8. protected $table = 'channel';
  9. /**
  10. * UUID 键名
  11. * @var string
  12. */
  13. protected $uuidKeyName = 'uid';
  14. protected $appends = [];
  15. /**
  16. * The "booted" method of the model.
  17. *
  18. * @return void
  19. */
  20. protected static function boot()
  21. {
  22. parent::boot();
  23. self::creating(function ($model) {
  24. $model->{$model->uuidKeyName} = self::generateId($model->uuidKeyName);
  25. });
  26. self::created(function ($model) {
  27. $uuid = hashEncodeId($model->id);
  28. $model->{$model->uuidKeyName} = $uuid;
  29. $model->save();
  30. });
  31. }
  32. /**
  33. * 关联1个应用.
  34. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  35. */
  36. public function app()
  37. {
  38. return $this->hasOne(AppModel::class, 'uid', 'mom_app_uid');
  39. }
  40. /**
  41. * 关联一个代理
  42. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  43. */
  44. public function agent()
  45. {
  46. return $this->belongsTo(AgentModel::class, 'uid', 'agent_uid');
  47. }
  48. public function agentName()
  49. {
  50. return $this->belongsTo(AgentModel::class, 'agent_uid','uid');
  51. }
  52. /**
  53. * 关联渠道包
  54. */
  55. public function channelRow()
  56. {
  57. return $this->hasOne(PackModel::class,'channel_code','uid');
  58. }
  59. }