read($card_no); if ($ret === false) { return true; } [$ch_name, $time, $state] = $ret; if (!in_array($ch_name, sending_monitor::$stChannelNames)) { //如果限制的通道发生变化了,过去的数据无效处理。 dcache('unique_sending_monitor', 'refill-', $card_no); return true; } if ($state === sending_monitor::SUCC) { if (time() - $time >= sending_monitor::SUCC_INTERVAL_SECS) { return true; } else { return false; } } elseif ($state === sending_monitor::SENDING) { return false; } else { return true; } } public function add($card_no, $chname) { if (!in_array($chname, sending_monitor::$stChannelNames)) { return; } $this->write($card_no, $chname, sending_monitor::SENDING); } public function success($card_no, $chname) { if (!in_array($chname, sending_monitor::$stChannelNames)) { return; } $this->write($card_no, $chname, sending_monitor::SENDING); } public function fail($card_no, $chname) { if (!in_array($chname, sending_monitor::$stChannelNames)) { return; } $name = 'unique_sending_monitor'; dcache($name, 'refill-', $card_no); } private function write($card_no, $chname, $state) { $name = 'unique_sending_monitor'; $data = [$card_no => json_encode([$chname, time(), $state])]; wcache($name, $data, 'refill-'); } private function read($card_no) { $name = 'unique_sending_monitor'; $ret = rcache($name, 'refill-', $card_no); if (empty($ret)) { return false; } $values = $ret[$card_no]; [$chname, $time, $state] = json_decode($values, true); return [$chname, $time, $state]; } }