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

77 lines
1.7 KiB

<?php
namespace App\Models\v3;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class Market extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_market';
protected $dateFormat = 'U';
public function setImgsAttribute($imgs)
{
if ($imgs){
$this->attributes['imgs'] = implode(',',$imgs);
}
}
public function getImgsAttribute($imgs)
{
return explode(',',$imgs);
}
public function mp(){
return $this->hasOne('\App\Models\LanzuMpInfo','id','mp_id');
}
/**
* 获取市场数组
*/
public static function getMarketArray($where = [], $options = [])
{
$model = self::whereNull('deleted_at');
// ->where('status',1)
if(!empty($where)){
$model->where($where);
}
$list = $model->pluck('id','name')->toArray();
if(!empty($options)){
$new = array_merge($options,$list);
return array_flip($new);
}else{
return array_flip($list);
}
}
/**
* 获取单个市场信息
*/
public static function getMarketInfo($id,$field = '*')
{
return self::select($field)->find($id);
}
/**
* 获取市场信息
* @return \Illuminate\Http\JsonResponse
*/
public static function getMarket()
{
$markets = self::select('id','name')
->where('status',1)
->whereNull('deleted_at')
->get();
$item = [];
foreach ($markets as $market) {
$item[$market->id] = $market->name;
}
return $item;
}
}