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

115 lines
2.7 KiB

<?php
namespace App\Models\v3;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class Store extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_store';
protected $dateFormat = 'U';
/* 查询记录数 limit */
protected $perPage = 10;
public static $_isRest= ['否','是'];
public static $_isOpen = ['关闭','开启'];
protected $appends = [
'logo_url',
'is_rest_text',
'is_open_text'
];
public function getLogoUrlAttribute($value)
{
$value = $value ? $value : $this->logo;
return $this->imageUrl($value);
}
public function getIsRestTextAttribute($value)
{
$value = $value ? $value : $this->is_rest;
return isset(self::$_onRest[$value]) ? self::$_onRest[$value] : '';
}
public function getIsOpenTextAttribute($value)
{
$value = $value ? $value : $this->is_iopen;
return isset(self::$_isOpen[$value]) ? self::$_isOpen[$value] : '';
}
/**
* 获取商家环境图片
* @param $value $this->environment
* @return array
*/
public function getEnvironmentAttribute($value)
{
$value = $value ? $value : $this->environmant;
return $value ? explode(',',$value) : [];
}
public function setEnvironmentAttribute($value)
{
$this->attributes['environment'] = implode(',',$value);
}
/**
* 是否开启店铺
*/
public function getIsOpenAttribute($value)
{
$value = $value ? $value : '';
return $value ? explode(',',$value) : [];
}
public function setIsOpenAttribute($value)
{
$this->attributes['is_open'] = 1;
}
/**
* 获取单个店铺信息
* @param int $id
* @param string $field
* @return string
*/
public static function getStoreInfo($id,$field = '*')
{
return self::select($field)->find($id);
}
/**
* 获取店铺数组
* id为键,name为值
* @return array
*/
public static function getStoreArray()
{
$list = self::select('id','name')
->where('status',2)
->whereNull('deleted_at')
->get();
$array = [];
if(count($list) > 0){
foreach ($list as $value) {
$array[$value->id] = $value->name;
}
}
return $array;
}
// 处理图片
public function imageUrl($value)
{
if(strripos($value,"http") === false){
return env('OSS_IMG_HOST').'/'.$value;
}else{
return $value;
}
}
}