123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace refill;
- class third_helper
- {
- private $mThirdJumps;
- private $mMchMixedPcodes;
- public function __construct()
- {
- $this->mThirdJumps = [];
- $this->mMchMixedPcodes = [];
- }
- public function load()
- {
- global $config;
- $this->mThirdJumps = $config['third_jumps'] ?? [];
- foreach ($this->mThirdJumps as $mchid => $jumps)
- {
- $pcodes = [];
- foreach ($jumps as $key => $val) {
- $pcodes[] = $key;
- $pcodes[] = $val;
- }
- $this->mMchMixedPcodes[$mchid] = array_unique($pcodes);
- }
- }
- public function third_retry(order $order): array
- {
- $next_pcoder = function ($mchid,$pcode)
- {
- if(array_key_exists($mchid,$this->mThirdJumps))
- {
- $jumps = $this->mThirdJumps[$mchid];
- if(array_key_exists($pcode,$jumps)) {
- $next_pcode = $jumps[$pcode];
- return [true,$next_pcode];
- }
- }
- return [false,''];
- };
- if($order->is_third())
- {
- $mchid = $order->mchid();
- $cur_pcode = $order->pcode();
- return $next_pcoder($mchid,$cur_pcode);
- } else {
- return [false,''];
- }
- }
- public function mixed($mchid, $pcode)
- {
- if (array_key_exists($mchid, $this->mMchMixedPcodes)) {
- return in_array($pcode, $this->mMchMixedPcodes[$mchid]);
- }
- return false;
- }
- }
|