BaseService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace addons\AvoidTax\common\service;
  3. use yii\base\BaseObject;
  4. /**
  5. * BaseService Class
  6. * @package addons\AvoidTax\common\service
  7. */
  8. class BaseService extends BaseObject
  9. {
  10. /**
  11. * @var string
  12. */
  13. public $error = '';
  14. /**
  15. * @var int
  16. */
  17. public $mall_id;
  18. /**
  19. * @var TaxConfigService
  20. */
  21. protected $config_service;
  22. /**
  23. * @var LuYongService
  24. */
  25. protected $ly_service;
  26. /**
  27. * @var AlipayService
  28. */
  29. protected $alipay_service;
  30. /**
  31. * @var XinLongService
  32. */
  33. protected $xl_service;
  34. /**
  35. * @return false
  36. */
  37. public function error($msg): bool
  38. {
  39. $this->error = $msg;
  40. return false;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getError()
  46. {
  47. return $this->error;
  48. }
  49. /**
  50. * @param array $params
  51. * @param string $field
  52. * @return integer
  53. */
  54. public function getPage(array $params, string $field = 'page') :int
  55. {
  56. return !empty($params[$field])
  57. ? $params[$field]
  58. : 1;
  59. }
  60. /**
  61. * @param array $params
  62. * @param string $field
  63. * @return integer
  64. */
  65. public function getLimit(array $params, string $field = 'limit') :int
  66. {
  67. return !empty($params[$field])
  68. ? $params[$field]
  69. : 20;
  70. }
  71. /**
  72. * @return TaxConfigService
  73. */
  74. public function getConfigService()
  75. {
  76. if (empty($this->config_service)) {
  77. return $this->config_service = new TaxConfigService(['mall_id' => $this->mall_id]);
  78. }
  79. return $this->config_service;
  80. }
  81. /**
  82. * @return LuYongService
  83. */
  84. public function getLyService()
  85. {
  86. if (empty($this->ly_service)) {
  87. return $this->ly_service = new LuYongService(['mall_id' => $this->mall_id]);
  88. }
  89. return $this->ly_service;
  90. }
  91. /**
  92. * @return AlipayService
  93. */
  94. public function getAlipayService()
  95. {
  96. if (empty($this->alipay_service)) {
  97. return $this->alipay_service = new AlipayService($this->mall_id);
  98. }
  99. return $this->alipay_service;
  100. }
  101. /**
  102. * @return XinlongService
  103. */
  104. public function getXlService()
  105. {
  106. if (empty($this->xl_service)) {
  107. return $this->xl_service = new XinlongService(['mall_id' => $this->mall_id]);
  108. }
  109. return $this->xl_service;
  110. }
  111. /**
  112. * 数组切割
  113. *
  114. * @param array $array
  115. * @param integer $limit
  116. * @return array
  117. */
  118. public static function arraySplice(array $array, int $limit = 10)
  119. {
  120. $offset = 0;
  121. $result = [];
  122. while ($value = array_slice($array, $offset, $limit)) {
  123. $result[] = $value;
  124. $offset += $limit;
  125. }
  126. return $result;
  127. }
  128. }