<?php
namespace Application\Service\DB\Item;

use Interop\Container\ContainerInterface;

class Cissclass extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        if (!$this->tableName) {
            $this->tableName = 'yikeen_item_cissclass';
        }

        parent::__construct($dbAdapter, $container);
    }


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

        return $datas;
    }
}