<?php
namespace DAO\GoodsClass;
/**
 * User: liuyuzhen
 * Date: 2019/1/23
 * Time: 16:18
 * Description:
 */
class StoreClassChargeLogModel extends \DAO\AbstractModel{
    /**
     * 表名
     *
     * @var string
     */
    protected $_tableName = 'han_store_class_charge_log';

    /**
     * 主键
     *
     * @var string
     */
    protected $_primaryKey = 'id';
    public function init(){

    }

    public function getList($where,$field){
        $this->setDb();
        return $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
    }

    public function insertBatch($datas){
        $this->setDb(\Our\DbNameConst::masterDBConnectName);
        $error = 0;
        $baseSql = "insert IGNORE into {$this->_tableName}(gc_id,store_id,old_end_time,new_start_time,new_end_time,service_fee,gmt_create,gmt_update,pay_sn,curr_month_fee,pre_month_fee,service_fee_sign) values";
        $insertAllSql = $baseSql;
        for ($i = 0; $i < count($datas); $i++) {
            $addSql = \Our\Common::format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}'),", $datas[$i]['gc_id'], $datas[$i]['store_id'], $datas[$i]['old_end_time'], $datas[$i]['new_start_time'], $datas[$i]['new_end_time'], $datas[$i]['service_fee'], $datas[$i]['gmt_create'], $datas[$i]['gmt_update'],$datas[$i]['pay_sn'], $datas[$i]['curr_month_fee'], $datas[$i]['pre_month_fee'], $datas[$i]['service_fee_sign']);
            $insertAllSql .= $addSql;
            if ($i % 1000 == 0 && $i != 0) {
                $insertAllSql = rtrim($insertAllSql, ',');
                $one = $this->db->insert($this->_tableName)->query($insertAllSql);
                if (!$one) {
                    $error++;
                }
                $insertAllSql = $baseSql;
            }
        }
        if ($insertAllSql != $baseSql) {
            $insertAllSql = rtrim($insertAllSql, ',');
            $one = $this->db->insert($this->_tableName)->query($insertAllSql);

            if (!$one) {
                $error++;
            }
        }
        if ($error > 0) {
            return false;
        }
        return true;
    }

    /**
     * 类实例
     *
     * @var \DAO\UserModel
     */
    private static $_instance = null;

    /**
     * 获取类实例
     *
     * @return \DAO\UserModel
     */
    public static function getInstance() {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
}
