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

92 lines
2.2 KiB

<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
use App\Models\ImsCjdcMarket as MarketModel;
use App\Models\StoreType as StoreTypeModel;
class Store extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_store';
protected $dateFormat = 'U';
protected $appends = [
'logo_url',
'market_name',
'store_type_name'
];
public function getMarketNameAttribute($value)
{
$value = $value ? $value : $this->market_id;
$market = MarketModel::getMarketInfo($value,'name');
return $market ? $market->name : '';
}
public function getStoreTypeNameAttribute($value)
{
$value = $value ? $value : $this->store_type_id;
$storeType = StoreTypeModel::getStoreTypeInfo($value,'type_name');
return $storeType ? $storeType->type_name : '';
}
public function getLogoUrlAttribute($value)
{
$value = $value ? $value : $this->logo;
return $this->imageUrl($value);
}
/**
* 获取商家环境图片
* @param $value $this->environment
* @return array
*/
public function getEnvironmentAttribute($value)
{
$value = $value ? $value : '';
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['IsOpen'] = 1;
}
/**
* 获取单个店铺信息
* @param int $id
* @param string $field
* @return string
*/
public static function getStoreInfo($id,$field = '*')
{
return self::select($field)->find($id);
}
// 处理图片
public function imageUrl($value)
{
if(strripos($value,"http") === false){
return env('OSS_IMG_HOST').'/'.$value;
}else{
return $value;
}
}
}