AppDeductionRuleModel.php 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Models\Mysql;
  3. class AppDeductionRuleModel extends BaseMysql
  4. {
  5. protected $table = 'app_deduction_rule';
  6. private static $appData = [];
  7. protected $appends = ['app_name'];
  8. /**
  9. * The "booted" method of the model.
  10. *
  11. * @return void
  12. */
  13. protected static function boot()
  14. {
  15. parent::boot();
  16. self::created(function ($model) {
  17. $uuid = hashEncodeId($model->id);
  18. $model->uid = $uuid;
  19. $model->save();
  20. });
  21. }
  22. /**
  23. * 获取应用名称
  24. *
  25. * directions 使用静态方法,获取app应用名称只会查询一次
  26. * @return \Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed
  27. */
  28. public function getAppNameAttribute()
  29. {
  30. if (empty(self::$appData)) {
  31. self::$appData = AppModel::query()->select('uid', 'name')->get()->keyBy('uid');
  32. }
  33. return $this->app_name = self::$appData[$this->app_uid]->name ?? '';
  34. }
  35. }