<?php

namespace app\admin\model;

use support\Db;
use support\Model;

/**
 * 套餐项目模型
 * Class Users
 * @packagegoods app\admin\model
 */
class Activity extends Model
{
    const ROLE_STATUS = 1;

    const IS_DEL_YES = 1;
    const IS_DEL_NO  = 0;
    const GOODS_IS_SHOW = [
        self::IS_DEL_YES => '已删除',
        self::IS_DEL_NO  => '未删除'
    ];
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'activity';

    public $timestamps = false;

    /**
     * Notes:获取活动列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: YCP
     * Date: 2023/2/23
     */
    public static function getActivityList(int $page, int $limit, string $keywords)
    {
        $list = static::select('*')
            ->where(['config_is_del'=>static::IS_DEL_NO])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('config_name', 'like', '%' . $keywords . '%');
            })
            ->orderBy('config_create_time','DESC')
            ->forPage($page, $limit)
            ->get();

        foreach ($list as &$value) {
            $value['activity_url'] = "https://service.wanyuewellness.cn/h5/#/?act=".$value['config_id'];
        }

        $count = static::where(['config_is_del'=>static::IS_DEL_NO])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('config_name', 'like', '%' . $keywords . '%');
            })
            ->count();
        return [$list, $count];
    }

    //时间格式
    public function getConfigCreateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }



}
