<?php
namespace app\api\logic;


use app\common\model\goods\Goods;
use app\common\model\home_service\HomeSpecial;
use app\common\logic\BaseLogic;
use think\facade\Db;


/**
 * HomeSpecial逻辑
 * Class HomeSpecialLogic
 * @package app\api\logic\home_service
 */
class HomeSpecialLogic extends BaseLogic
{

    /**
     * @param array $where
     * @param int $limit
     * @param array $userInfo
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getLists(array $where, int $limit, array $userInfo,$domain)
    {
       return HomeSpecial::where($where)
            ->field('id,cover_type,cover,title,vue_web,vue_param')
            ->order('weight desc')
            ->limit($limit)
            ->select()
           ->each(function($item) use ($userInfo,$domain){
               if($item->goods_id){
                   $item->goods = Goods::where('id',$item->goods_id)->field('goods_banners,goods_name,service_total,service_fee')->findOrEmpty();
               }
               if($item->vue_web=='pages/preview/videoPre' || $item->vue_web=='pages/preview/imagePre' || $item->vue_web=='pages/preview/richView'){
                   $item->vue_param = 'id='.$item->id;
               }
               if($item->vue_web=='pages/web_view/index'){
                   $token = !empty($userInfo['token'])?$userInfo['token']:'';
                   $item->vue_param = 'hrefUrl='.rawurlencode($domain.'/static/wxapp/H5/adver5/index.html?property_activity_id=14&token='.$token);
               }
           })
            ->toArray();
    }

    /**
     * @notes 获取详情
     * @param $params
     * @return array
     * @author likeadmin
     * @date 2024/11/18 10:05
     */
    public static function detail($params): array
    {
        return HomeSpecial::field('cover_type,cover,title,describe,content')->findOrEmpty($params['id'])->toArray();
    }
}