<?php

namespace app\extra\service\blue;

use app\extra\basic\Service;
use app\model\blue\BlueExpert;

class ExpertService extends Service
{

    public array $source = [
        "douyin"        => "抖音",
        "kuaishou"      => "快手",
        "xiaohongshu"   => "小红书",
        "tengxun"       => "视频号"
    ];

    /**
     * 列表
     * @param array $param
     */
    public function getList(array $param = [])
    {
        $this->mode = new BlueExpert();
        return $this->searchVal($param,$this->searchFilter($param))->with(['platform' => function($query){
            $query->field("openid,source")->append(['source_name'])->withAttr(['source_name' => function($data,$resp){
                return $this->source[$resp['source']];
            }]);
        }])->paginate([
            "list_rows" => $param['pageSize'],
            "page"      => $param['page']
        ]);
    }


    /**
     *
     * @param array $param
     * @return array
     */
    public function searchFilter(array $param = []): array
    {
        $filter = [];
        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
        !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
        !empty($param['truename']) && $filter[] = ["truename", 'like', "%{$param['truename']}%"];
        return $filter;
    }


}