链街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.

145 lines
3.7 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
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. 'is_operation'
  22. ];
  23. public function getIsOperationAttribute($value)
  24. {
  25. $value = $value ? $value : $this->is_rest;
  26. return $value == 1 ? 0 : 1;
  27. }
  28. public function getLogoUrlAttribute($value)
  29. {
  30. $value = $value ? $value : $this->logo;
  31. return $this->imageUrl($value);
  32. }
  33. public function getIsRestTextAttribute($value)
  34. {
  35. $value = $value ? $value : $this->is_rest;
  36. return isset(self::$_ISREST[$value]) ? self::$_ISREST[$value] : '';
  37. }
  38. public function getIsOpenTextAttribute($value)
  39. {
  40. $value = $value ? $value : $this->is_iopen;
  41. return isset(self::$_ISOPEN[$value]) ? self::$_ISOPEN[$value] : '';
  42. }
  43. /**
  44. * 获取商家环境图片
  45. * @param $value $this->environment
  46. * @return array
  47. */
  48. public function getEnvironmentAttribute($value)
  49. {
  50. $value = $value ? $value : $this->environmant;
  51. return $value ? explode(',',$value) : [];
  52. }
  53. public function setEnvironmentAttribute($value)
  54. {
  55. $this->attributes['environment'] = implode(',',$value);
  56. }
  57. /**
  58. * 获取单个店铺信息
  59. * @param int $id
  60. * @param string $field
  61. * @return string
  62. */
  63. public static function getStoreInfo($id,$field = '*')
  64. {
  65. return self::select($field)->find($id);
  66. }
  67. /**
  68. * 获取店铺数组
  69. * id为键,name为值
  70. * @return array
  71. */
  72. public static function getStoreArray($where = [], $options = [])
  73. {
  74. $model = self::select('id','name')
  75. ->where('status',2)
  76. ->whereNull('deleted_at');
  77. if(count($where) > 0){
  78. $model->where($where);
  79. }
  80. $list = $model->get();
  81. $array = [];
  82. if(count($list) > 0){
  83. foreach ($list as $value) {
  84. $array[$value->id] = $value->name;
  85. }
  86. }
  87. return $array;
  88. }
  89. // 处理图片
  90. public function imageUrl($value)
  91. {
  92. if(strripos($value,"http") === false){
  93. return config('filesystems.disks.oss.img_host').'/'.$value;
  94. }else{
  95. return $value;
  96. }
  97. }
  98. // 关联旧流水
  99. public function storeAccount()
  100. {
  101. return $this->belongsTo('App\Models\v3\StoreAccount','store_id','id','light');
  102. }
  103. // 关联流水
  104. public function financialRecord0()
  105. {
  106. return $this->belongsTo('App\Models\FinancialRecord0','user_id','user_id','light');
  107. }
  108. // 关联流水
  109. public function financialRecord1()
  110. {
  111. return $this->belongsTo('App\Models\FinancialRecord1','user_id','user_id','light');
  112. }
  113. // 关联流水
  114. public function financialRecord2()
  115. {
  116. return $this->belongsTo('App\Models\FinancialRecord2','user_id','user_id','light');
  117. }
  118. // 关联流水
  119. public function financialRecord3()
  120. {
  121. return $this->belongsTo('App\Models\FinancialRecord3','user_id','user_id','light');
  122. }
  123. // 关联流水
  124. public function financialRecord4()
  125. {
  126. return $this->belongsTo('App\Models\FinancialRecord4','user_id','user_id','light');
  127. }
  128. }