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

namespace Application\Service\DB\Item;

use Interop\Container\ContainerInterface;

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


    /**
     * Notes:获取指定条件下的数据
     * User: lltyy
     * DateTime: 2024/5/28 9:50
     *
     * @param string $where 条件
     * @param string[] $columns 字段
     * @param string[] $order 排序
     * @param string $key 键值
     * @param int $is_more 是否有多笔【1 是 0 否】
     * @return array
     */
    public function fetchDataByKey($where='is_del = 0',$columns=['id'],$order=['id'],$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($key == 'user_id'){
                    $data_keys = !empty($data_key) ? explode(',',$data_key) : [];
                    foreach($data_keys as $data_keyid){
                        if($is_more == 1){
                            $datas[$data_keyid][] = $infoData;
                        }else{
                            $datas[$data_keyid] = $infoData;
                        }
                    }
                }else{
                    if($is_more == 1){
                        $datas[$data_key][] = $infoData;
                    }else{
                        $datas[$data_key] = $infoData;
                    }
                }
            }
        }
        unset($cond);
        unset($infoDatas);
        return $datas;
    }


}