Commit 894646fe authored by liuyuzhengrace's avatar liuyuzhengrace

计算免费月份数据

parent f73df66e
This diff is collapsed.
......@@ -29,33 +29,35 @@ class StoreClassChargeLogModel extends \DAO\AbstractModel{
return $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
}
/**
* 计算分类对应
* @param $class
* @param $storeEndTime
* @param int $month
* @return array|bool
*/
public function getFreeChargeMoney($class,$storeEndTime,$month=1){
if($month<=0){
return false;
}
$currentTime = mktime(23,59,59,date('m'),date('d'),date('Y'));
$tempOldTime = max(array($storeEndTime,$class['deadline']));
$oldTime = mktime(23,59,59,date('m',$tempOldTime),date('d',$tempOldTime),date('Y',$tempOldTime));
$currExpTime = $oldTime;
if($currentTime>$oldTime){
$currExpTime = $currentTime;
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;
}
}
$currentMonthEnd = mktime(0,0,0,(date('m',$currExpTime)+1),1,date('Y',$currExpTime))-1;
$endTime = mktime(0,0,0,(date('m',$currExpTime)+1+$month),1,date('Y',$currExpTime))-1;
if($currentMonthEnd>$currExpTime){
$endTime = $currentMonthEnd;
if($month>1){
$endTime = mktime(0,0,0,(date('m',$currExpTime)+$month),1,date('Y',$currExpTime))-1;
if ($insertAllSql != $baseSql) {
$insertAllSql = rtrim($insertAllSql, ',');
$one = $this->db->insert($this->_tableName)->query($insertAllSql);
if (!$one) {
$error++;
}
}
return array('service_fee'=>0,'old_end_time'=>$tempOldTime,'new_start_time'=>$currExpTime+1,'new_end_time'=>$endTime,'curr_month_fee'=>0,'pre_month_fee'=>0);
if ($error > 0) {
return false;
}
return true;
}
/**
......
......@@ -29,7 +29,7 @@ class QmStoreClassModel extends \DAO\AbstractModel{
public function selectByWhere($where = null,$field = '*',$limit=false){
$this->setDb();
$this->setDb($this->dbName);
if(is_array($where)){
$where = $this->db->getSqlWhereByArray($where);
}
......@@ -41,6 +41,7 @@ class QmStoreClassModel extends \DAO\AbstractModel{
return $result;
}
public function delSignScopeCache($storeId){
$result = \Our\RedisHelper::delCachedFunction(\Redis\Db6\QmStoreClassRedisModel::getInstance(),array(&$this, 'selectByWhere'),array(),array($storeId));
return $result;
......@@ -80,6 +81,14 @@ class QmStoreClassModel extends \DAO\AbstractModel{
return $list;
}
public function update($data,$where){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$result=$this->db->update($this->_tableName)->rows($data)->where($where)->execute();
return $result;
}
/**
* 类实例
*/
......@@ -88,21 +97,21 @@ class QmStoreClassModel extends \DAO\AbstractModel{
/**
* 获取类实例
*/
public static function getInstance() {
public static function getInstance($dbName = \Our\DbNameConst::salveDBConnectName) {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
self::$_instance = new self($dbName);
}
return self::$_instance;
}
public function getStoreClasses($where, $field = '*'){
$this->setDb();
$this->setDb($this->dbName);
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
return $result;
}
public function getStoreSignClasses($where,$field = "*"){
$this->setDb();
$this->setDb($this->dbName);
if(is_array($where)){
$where = $this->db->getSqlWhereByArray($where);
}
......@@ -137,11 +146,4 @@ class QmStoreClassModel extends \DAO\AbstractModel{
\Our\RedisHelper::delCachedFunction(\Redis\Db6\QmStoreClassRedisModel::getInstance(), array(&$this, 'getStoreClasses'),array(),array($cityCode));
}
public function update($data,$where){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$result=$this->db->update($this->_tableName)->rows($data)->where($where)->execute();
return $result;
}
}
\ No newline at end of file
......@@ -31,6 +31,40 @@ class StoreClassPayLogModel extends \DAO\AbstractModel
$this->setDb($this->dbName);
return $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
}
public function insertBatch($datas){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0;
$baseSql = "insert IGNORE into {$this->_tableName}(store_id,pay_state,pay_sn,pay_content,gmt_create,pay_time,pay_amount,pay_type,gmt_update) values";
$insertAllSql = $baseSql;
for ($i = 0; $i < count($datas); $i++) {
$addSql = \Our\Common::format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}'),", $datas[$i]['store_id'], $datas[$i]['pay_state'], $datas[$i]['pay_sn'], $datas[$i]['pay_content'], $datas[$i]['gmt_create'], $datas[$i]['pay_time'], $datas[$i]['pay_amount'], $datas[$i]['pay_type'],$datas[$i]['gmt_update']);
$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;
}
/**
* 类实例
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment