74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||
// +----------------------------------------------------------------------
|
||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||
// +----------------------------------------------------------------------
|
||
namespace app\api\model\wdsxh\member;
|
||
|
||
use think\Model;
|
||
|
||
class CompanyGoods extends Model
|
||
{
|
||
// 表名
|
||
protected $name = 'wdsxh_company_goods';
|
||
|
||
// 自动写入时间戳字段
|
||
protected $autoWriteTimestamp = true;
|
||
|
||
// 定义时间戳字段名
|
||
protected $createTime = 'createtime';
|
||
protected $updateTime = 'updatetime';
|
||
|
||
// 追加属性
|
||
protected $append = ['image'];
|
||
|
||
/**
|
||
* 获取第一张图片(完整URL)
|
||
* @param $value
|
||
* @param $data
|
||
* @return string
|
||
*/
|
||
public function getImageAttr($value, $data)
|
||
{
|
||
if (!isset($data['images']) || empty($data['images'])) {
|
||
return '';
|
||
}
|
||
|
||
$images = $data['images'];
|
||
$firstImage = '';
|
||
|
||
// 判断是否为JSON数组
|
||
if (is_string($images) && (strpos($images, '[') === 0 || strpos($images, '{') === 0)) {
|
||
$imagesArray = json_decode($images, true);
|
||
if (is_array($imagesArray) && !empty($imagesArray)) {
|
||
$firstImage = is_array($imagesArray[0]) ? $imagesArray[0] : reset($imagesArray);
|
||
}
|
||
}
|
||
// 判断是否为逗号分隔的字符串
|
||
elseif (is_string($images) && strpos($images, ',') !== false) {
|
||
$imagesArray = explode(',', $images);
|
||
$firstImage = trim($imagesArray[0]);
|
||
}
|
||
// 单个图片
|
||
else {
|
||
$firstImage = $images;
|
||
}
|
||
|
||
// 返回完整URL
|
||
return wdsxh_full_url($firstImage);
|
||
}
|
||
|
||
protected function getImagesAttr($value)
|
||
{
|
||
$array = explode(',',$value);
|
||
foreach ($array as $k=>$v) {
|
||
$array[$k] = wdsxh_full_url($v);
|
||
}
|
||
return implode(',',$array);
|
||
}
|
||
} |