<?php
/**
 *
 * @author：llbjj
 * @DateTime：2022/5/6 10:57
 * @Description：
 *
 */

namespace Application\Service\DB\Collect;

use Interop\Container\ContainerInterface;

class Category extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_collect_category';
        parent::__construct($dbAdapter, $container);
    }


    /**
     * Notes: 获取指定条件下的数据
     * User: lltyy
     * DateTime: 2023/4/25 10:16
     *
     * @param $where
     * @param $where
     * @return array
     */
    public function fetchDataByKey($where='is_del = 0',$columns=['id'],$order=['pid','category_order'],$key='id',$is_more=0){
        $datas = [];
        $cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>$order
        ];
        $infoDatas = $this->fetchAll($cond);
        if(!empty($infoDatas)){
            foreach($infoDatas as $infoData){
                $data_key = $infoData[$key];
                if($is_more == 1){
                    $datas[$data_key][] = $infoData;
                }else{
                    $datas[$data_key] = $infoData;
                }
            }
        }
        unset($cond);
        unset($infoDatas);
        return $datas;
    }

    /**
     * Notes:获取指定条件下的下拉选择数据
     * User: lltyy
     * DateTime: 2024/3/18 11:32
     *
     * @param string $where
     * @return mixed
     */
    public function fetchSelectData($where='is_del = 0 and pid = 0'){
        $cond = [
            'where'=>$where,
            'columns'=>['value'=>'id','label'=>'category_name'],
            'order'=>['pid','category_order']
        ];
        $datas = $this->fetchAll($cond);
        return $datas;
    }
}