<?php
declare (strict_types = 1);

namespace app\admin\controller\v1;

use app\admin\model\v1\ProductInquiryModel;

/**
 * 产品询盘记录控制器
 */
class ProductInquiry
{
    // 分页
    public function index()
    {
        $param = request()->param([
            'corp_name',
            'country_name',
            'created_at',
            'page/d' => 1,
            'size/d' => 10
        ]);

        $msgs = ProductInquiryModel::field([
                'id',
                'first_name',
                'last_name',
                'email',
                'phone',
                'corp_name',
                'country_name',
                'industry',
                'message',
                'created_at'
            ])
            ->withSearch(['corp_name', 'country_name', 'created_at'], [
                'corp_name'    => $param['corp_name'] ?? null,
                'country_name' => $param['country_name'] ?? null,
                'created_at'   => !empty($param['created_at']) ? explode(',', $param['created_at']) : null,
            ])
            ->language(request()->lang_id)
            ->order(['id' => 'desc'])
            ->paginate([
                'list_rows' => $param['size'],
                'page'      => $param['page'],
            ]);

        return success('获取成功', $msgs);
    }
}
