| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace addons\AvoidTax\common\service;
- use yii\base\BaseObject;
- /**
- * BaseService Class
- * @package addons\AvoidTax\common\service
- */
- class BaseService extends BaseObject
- {
- /**
- * @var string
- */
- public $error = '';
- /**
- * @var int
- */
- public $mall_id;
- /**
- * @var TaxConfigService
- */
- protected $config_service;
- /**
- * @var LuYongService
- */
- protected $ly_service;
- /**
- * @var AlipayService
- */
- protected $alipay_service;
- /**
- * @var XinLongService
- */
- protected $xl_service;
- /**
- * @return false
- */
- public function error($msg): bool
- {
- $this->error = $msg;
- return false;
- }
- /**
- * @return string
- */
- public function getError()
- {
- return $this->error;
- }
- /**
- * @param array $params
- * @param string $field
- * @return integer
- */
- public function getPage(array $params, string $field = 'page') :int
- {
- return !empty($params[$field])
- ? $params[$field]
- : 1;
- }
- /**
- * @param array $params
- * @param string $field
- * @return integer
- */
- public function getLimit(array $params, string $field = 'limit') :int
- {
- return !empty($params[$field])
- ? $params[$field]
- : 20;
- }
- /**
- * @return TaxConfigService
- */
- public function getConfigService()
- {
- if (empty($this->config_service)) {
- return $this->config_service = new TaxConfigService(['mall_id' => $this->mall_id]);
- }
- return $this->config_service;
- }
- /**
- * @return LuYongService
- */
- public function getLyService()
- {
- if (empty($this->ly_service)) {
- return $this->ly_service = new LuYongService(['mall_id' => $this->mall_id]);
- }
- return $this->ly_service;
- }
- /**
- * @return AlipayService
- */
- public function getAlipayService()
- {
- if (empty($this->alipay_service)) {
- return $this->alipay_service = new AlipayService($this->mall_id);
- }
- return $this->alipay_service;
- }
- /**
- * @return XinlongService
- */
- public function getXlService()
- {
- if (empty($this->xl_service)) {
- return $this->xl_service = new XinlongService(['mall_id' => $this->mall_id]);
- }
- return $this->xl_service;
- }
- /**
- * 数组切割
- *
- * @param array $array
- * @param integer $limit
- * @return array
- */
- public static function arraySplice(array $array, int $limit = 10)
- {
- $offset = 0;
- $result = [];
- while ($value = array_slice($array, $offset, $limit)) {
- $result[] = $value;
- $offset += $limit;
- }
- return $result;
- }
- }
|