$time,'riseNum'=>1,'totalNum'=>1,'merchantId'=>$merchantId]; self::add($data); }else{ $newRiseNum = $order['riseNum'] + 1; $newTotalNum = $order['totalNum'] + 1; $data = ['riseNum'=>$newRiseNum,'totalNum'=>$newTotalNum]; self::updateByIds($time, $merchantId, $data); } return $data; } public static function updateByIds($time,$merchantId,$data) { xhOrderDayNum::updateByCondition(['time'=>$time,'merchantId'=>$merchantId], $data); self::getByIds($time, $merchantId); $cacheKey = configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId; $params = [$cacheKey]; if(!empty($data)){ foreach($data as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); } public static function add($data) { $return = xhOrderDayNum::add($data); $merchantId = $return['merchantId']; $time = $return['time']; $cacheKey = configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId; $params = [$cacheKey]; if(!empty($return)){ foreach($return as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); return $return; } public static function getByIds($time,$merchantId) { $cacheKey = configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId; $order = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]); if(!empty($order)){ $arr = []; $i = 0; $x = 0; foreach($order as $key => $val){ $i++; if($i%2 == 0){ $arr[$x]['value'] = $val; $x++; }else{ $arr[$x]['key'] = $val; } } $orderArr = []; foreach($arr as $key => $val){ $orderArr[$val['key']] = $val['value']; } unset($orderArr['info_already_get_by_sql']); return $orderArr; } $order = xhOrderDayNum::find()->where(['time'=>$time,'merchantId'=>$merchantId])->asArray()->one(); $params = [$cacheKey]; $params[] = 'info_already_get_by_sql'; $params[] = 'ok';//redis没有办法设置带空值的键,加此可以数据空时表示取过 if(!empty($order)){ foreach($order as $key => $val){ $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET',$params); return $order; } }