Advertisement.php 2.9 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:广告 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models
 * @package   App\Models
 * @author    Richer <yangzi1028@163.com>
 * @date      2023年4月20日13:48:05
 * @copyright 2014-2023 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models;

use App\Models\User\User;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Class Advertisement
 * @package App\Models
 */
class Advertisement extends BaseModel
{
    // 指定数据库表
    const TABLE = 'advertisements';
    protected $table = self::TABLE ;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME = 'advertisement';
    const OBJ_NAME_ZH = '广告';

    /**
     * 类型业务常量配置
     */
    const DYSFUNCTION   = 1;// 功能异常
    const OTHER_PROBLEM = 99;// 其他问题

    /**
     * 类型业务常量配置[1 => '功能异常', 992 => '其他问题']
     */
    const TYPE_OPTIONS = [
        self::DYSFUNCTION    => '功能异常',
        self::OTHER_PROBLEM   => '其他问题',
    ];

    /**
     * @param $value
     */
    public function setImagesAttribute($value)
    {
        // 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
        $this->attributes['images'] = my_json_encode(substr_file_path($value));
    }

    /**
     * @param string $value 值
     *
     * @return array
     * @throws GuzzleException
     */
    public function getImagesAttribute($value): array
    {
        return splice_file_path(json_decode($value, true)) ?: [];
    }

    /**
     * @param $value
     */
    public function setCoverImageAttribute($value)
    {
        // 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
        $this->attributes['cover_image'] = substr_file_path($value);
    }

    /**
     * @param string $value 值
     *
     * @return array
     * @throws GuzzleException
     */
    public function getCoverImageAttribute($value)
    {
        return splice_file_path($value);
    }

//    /**
//     * @param $value
//     */
//    public function setBodyAttribute($value)
//    {
//        // 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
//        $this->attributes['body'] = substr_file_path($value);
//    }
//
//    /**
//     * @param string $value 值
//     *
//     * @return array
//     * @throws GuzzleException
//     */
//    public function getBodyAttribute($value)
//    {
//        return splice_file_path($value);
//    }
}