<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

class PlatformSelect extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = Db::name('platform_select');
    }

    /**
     * 平台甄选列表
     * @return void
     */
    public function getList()
    {
        try {
            $field = 'id,title,image,createtime';
            $where['status'] = 1;
            $result = $this->model->field($field)->where($where)->order('createtime desc')->autopage()->select();
            if (!empty($result)) {
                foreach ($result as $key => &$value) {
                    $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i:s',$value['createtime']) : '';
                }
                $result = list_domain_image($result,['image']);
            }
            $this->success('获取成功',$result);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }

    /**
     * 平台甄选详情
     * @return void
     */
    public function getInfo()
    {
        try {
            $id = $this->request->param('id',0);
            $field = 'id,title,image,content,createtime';
            $where['status'] = 1;
            $where['id'] = $id;
            $result = $this->model->field($field)->where($where)->find();
            if (!empty($result)) {
                $result['createtime'] = !empty($result['createtime']) ? date('Y.m.d H:i:s',$result['createtime']) : '';
                $result = info_domain_image($result,['image']);
            }
            $this->success('获取成功',$result);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }
}