third_helper.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace refill;
  3. class third_helper
  4. {
  5. private $mThirdJumps;
  6. private $mMchMixedPcodes;
  7. public function __construct()
  8. {
  9. $this->mThirdJumps = [];
  10. $this->mMchMixedPcodes = [];
  11. }
  12. public function load()
  13. {
  14. global $config;
  15. $this->mThirdJumps = $config['third_jumps'] ?? [];
  16. foreach ($this->mThirdJumps as $mchid => $jumps)
  17. {
  18. $pcodes = [];
  19. foreach ($jumps as $key => $val) {
  20. $pcodes[] = $key;
  21. $pcodes[] = $val;
  22. }
  23. $this->mMchMixedPcodes[$mchid] = array_unique($pcodes);
  24. }
  25. }
  26. public function third_retry(order $order): array
  27. {
  28. $next_pcoder = function ($mchid,$pcode)
  29. {
  30. if(array_key_exists($mchid,$this->mThirdJumps))
  31. {
  32. $jumps = $this->mThirdJumps[$mchid];
  33. if(array_key_exists($pcode,$jumps)) {
  34. $next_pcode = $jumps[$pcode];
  35. return [true,$next_pcode];
  36. }
  37. }
  38. return [false,''];
  39. };
  40. if($order->is_third())
  41. {
  42. $mchid = $order->mchid();
  43. $cur_pcode = $order->pcode();
  44. return $next_pcoder($mchid,$cur_pcode);
  45. } else {
  46. return [false,''];
  47. }
  48. }
  49. public function mixed($mchid, $pcode)
  50. {
  51. if (array_key_exists($mchid, $this->mMchMixedPcodes)) {
  52. return in_array($pcode, $this->mMchMixedPcodes[$mchid]);
  53. }
  54. return false;
  55. }
  56. }