123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace refill;
- abstract class IRefill
- {
- protected $mName;
- protected $mStoreID;
- protected $mRefillType;
- protected $mOfficialSN;
- protected $mCardType = [];
- protected $mAmounts = [];
- protected $mPeriod;
- protected $mOpened;
- protected $mSort;
- public function __construct($cfgs)
- {
- $this->mName = $cfgs['name'];
- $this->mStoreID = $cfgs['store_id'];
- $this->mRefillType = $cfgs['refill_type'];
- foreach ( $cfgs['amount'] as $k => $v) {
- $this->mAmounts[$k] = $v;
- }
- $this->mPeriod = $cfgs['period'];
- $this->mOfficialSN = $cfgs['official_sn'] ?? false;
- $this->mOpened = true;
- $this->mSort = 65536;
- }
- abstract public function add($card_no,$card_type,$amount,$params);
- abstract public function query($refill_info);
- public function name() {
- return $this->mName;
- }
- public function store_id() {
- return $this->mStoreID;
- }
- public function official_sn() {
- return $this->mOfficialSN === true;
- }
- public function callback() {
- return true;
- }
- public function refill_type() {
- return $this->mRefillType;
- }
- protected function match_period()
- {
- $period = $this->mPeriod;
- if(empty($period)) {
- return true;
- }
- $cur_time = time();
- $date = date('Y-m-d',$cur_time);
- $day_start = strtotime("{$date} {$period['start']}");
- if(empty($period['end'])) {
- $day_end = strtotime("{$date}") + 86400;
- }
- else {
- $day_end = strtotime("{$date} {$period['end']}");
- }
- return ($cur_time >= $day_start && $cur_time < $day_end);
- }
- public function amounts()
- {
- return $this->mAmounts;
- }
- public function goods(int $amout)
- {
- if(array_key_exists($amout,$this->mAmounts)) {
- $params = $this->mAmounts[$amout];
- return [$params['goods_id'], round($params['price'],2)];
- }
- else {
- return [];
- }
- }
- public function setOpened(bool $opened) {
- $this->mOpened = $opened;
- }
- public function opened() {
- return $this->mOpened;
- }
- public function setSort(int $sort) {
- $this->mSort = $sort;
- }
- public function sort() {
- return $this->mSort;
- }
- public function check(int $amount,int $card_type) : array
- {
- if(!array_key_exists($amount,$this->mAmounts)) {
- return [false,'额度不支持'];
- }
- if(!in_array($card_type,$this->mCardType)) {
- return [false,'不支持该类型'];
- }
- if(!$this->match_period()) {
- return [false,'不在充值时间范围内'];
- }
- return [true,'success'];
- }
- protected function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- }
|