链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Store extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. public static $tableName = 'lanzu_store';
  11. protected $table = 'lanzu_store';
  12. protected $dateFormat = 'U';
  13. /* 查询记录数 limit */
  14. protected $perPage = 10;
  15. public static $_ISREST= ['否','是'];
  16. public static $_ISOPEN = ['关闭','开启'];
  17. protected $appends = [
  18. 'logo_url',
  19. 'is_rest_text',
  20. 'is_open_text'
  21. ];
  22. public function getLogoUrlAttribute($value)
  23. {
  24. $value = $value ? $value : $this->logo;
  25. return $this->imageUrl($value);
  26. }
  27. public function getIsRestTextAttribute($value)
  28. {
  29. $value = $value ? $value : $this->is_rest;
  30. return isset(self::$_ISREST[$value]) ? self::$_ISREST[$value] : '';
  31. }
  32. public function getIsOpenTextAttribute($value)
  33. {
  34. $value = $value ? $value : $this->is_iopen;
  35. return isset(self::$_ISOPEN[$value]) ? self::$_ISOPEN[$value] : '';
  36. }
  37. /**
  38. * 获取商家环境图片
  39. * @param $value $this->environment
  40. * @return array
  41. */
  42. public function getEnvironmentAttribute($value)
  43. {
  44. $value = $value ? $value : $this->environmant;
  45. return $value ? explode(',',$value) : [];
  46. }
  47. public function setEnvironmentAttribute($value)
  48. {
  49. $this->attributes['environment'] = implode(',',$value);
  50. }
  51. /**
  52. * 获取单个店铺信息
  53. * @param int $id
  54. * @param string $field
  55. * @return string
  56. */
  57. public static function getStoreInfo($id,$field = '*')
  58. {
  59. return self::select($field)->find($id);
  60. }
  61. /**
  62. * 获取店铺数组
  63. * id为键,name为值
  64. * @return array
  65. */
  66. public static function getStoreArray($where = [], $options = [])
  67. {
  68. $model = self::select('id','name')
  69. ->where('status',2)
  70. ->whereNull('deleted_at');
  71. if(count($where) > 0){
  72. $model->where($where);
  73. }
  74. $list = $model->get();
  75. $array = [];
  76. if(count($list) > 0){
  77. foreach ($list as $value) {
  78. $array[$value->id] = $value->name;
  79. }
  80. }
  81. return $array;
  82. }
  83. // 处理图片
  84. public function imageUrl($value)
  85. {
  86. if(strripos($value,"http") === false){
  87. return config('filesystems.disks.oss.img_host').'/'.$value;
  88. }else{
  89. return $value;
  90. }
  91. }
  92. // 关联旧流水
  93. public function storeAccount()
  94. {
  95. return $this->belongsTo('App\Models\v3\StoreAccount','store_id','id','light');
  96. }
  97. // 关联流水
  98. public function financialRecord0()
  99. {
  100. return $this->belongsTo('App\Models\FinancialRecord0','user_id','user_id','light');
  101. }
  102. // 关联流水
  103. public function financialRecord1()
  104. {
  105. return $this->belongsTo('App\Models\FinancialRecord1','user_id','user_id','light');
  106. }
  107. // 关联流水
  108. public function financialRecord2()
  109. {
  110. return $this->belongsTo('App\Models\FinancialRecord2','user_id','user_id','light');
  111. }
  112. // 关联流水
  113. public function financialRecord3()
  114. {
  115. return $this->belongsTo('App\Models\FinancialRecord3','user_id','user_id','light');
  116. }
  117. // 关联流水
  118. public function financialRecord4()
  119. {
  120. return $this->belongsTo('App\Models\FinancialRecord4','user_id','user_id','light');
  121. }
  122. }