RecordsModel.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: king/QQ:995265288
  5. * Date: 2019-07-08
  6. * Time: 10:30
  7. */
  8. namespace app\backend\models\excelRecharge;
  9. use app\common\scopes\UniacidScope;
  10. class RecordsModel extends \app\common\models\excelRecharge\RecordsModel
  11. {
  12. protected $appends = ['sourceName'];
  13. public static function boot()
  14. {
  15. parent::boot();
  16. self::addGlobalScope(new UniacidScope());
  17. }
  18. /**
  19. * 通过字段 source 输出 sourceName
  20. *
  21. * @return string
  22. * @Author yitian
  23. */
  24. public function getSourceNameAttribute()
  25. {
  26. return $this->getSourceNameComment($this->attributes['source']);
  27. }
  28. /**
  29. * @param $source
  30. * @return mixed|string
  31. */
  32. public function getSourceNameComment($source)
  33. {
  34. return isset($this->sourceComment()[$source]) ? $this->sourceComment()[$source] : '';
  35. }
  36. /**
  37. * @return array
  38. */
  39. public function sourceComment()
  40. {
  41. return [
  42. 'balance' => '余额',
  43. 'point' => '积分',
  44. 'love' => $this->loveName()
  45. ];
  46. }
  47. /**
  48. * @return string
  49. */
  50. private function loveName()
  51. {
  52. if (app('plugins')->isEnabled('love')) {
  53. return LOVE_NAME;
  54. }
  55. return "爱心值";
  56. }
  57. }