Files
yycea/application/api/model/wdsxh/member/CompanyGoods.php
2026-03-17 09:56:06 +08:00

74 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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);
}
}