CrmebServeServices.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services;
  12. use app\common\repositories\system\config\ConfigValueRepository;
  13. use crmeb\services\express\Express;
  14. use crmeb\services\product\Product;
  15. use crmeb\services\serve\Serve;
  16. use crmeb\services\sms\Sms;
  17. use think\facade\Cache;
  18. /**
  19. * 平台服务入口
  20. * Class ServeServices
  21. * @package crmeb\services
  22. */
  23. class CrmebServeServices
  24. {
  25. public $merId;
  26. public function __construct(int $merId = 0)
  27. {
  28. $this->merId = $merId;
  29. }
  30. /**
  31. * 获取配置
  32. * @return array
  33. */
  34. public function getConfig(array $config = [])
  35. {
  36. $argc = [
  37. 'account' => merchantConfigNoCache($this->merId,'serve_account'),
  38. 'secret' => merchantConfigNoCache($this->merId,'serve_token'),
  39. 'merId' => $this->merId,
  40. ];
  41. return array_merge($argc, $config);
  42. }
  43. /**
  44. * 短信
  45. * @return Sms
  46. */
  47. public function sms(array $config = [])
  48. {
  49. return app()->make(Sms::class, [$this->getConfig($config)]);
  50. }
  51. /**
  52. * 复制商品
  53. * @return Product
  54. */
  55. public function copy(array $config = [])
  56. {
  57. return app()->make(Product::class, [$this->getConfig($config)]);
  58. }
  59. /**
  60. * 电子面单
  61. * @return Express
  62. */
  63. public function express(array $config = [])
  64. {
  65. return app()->make(Express::class, [$this->getConfig($config)]);
  66. }
  67. /**
  68. * 用户
  69. * @return Serve
  70. */
  71. public function user(array $config = [])
  72. {
  73. return app()->make(Serve::class, [$this->getConfig($config)]);
  74. }
  75. /**
  76. * 获取短信模板
  77. * @param int $page
  78. * @param int $limit
  79. * @param int $type
  80. * @return array
  81. */
  82. public function getSmsTempsList(int $page, int $limit, int $type)
  83. {
  84. $list = $this->sms()->temps($page, $limit, $type);
  85. foreach ($list['data'] as &$item) {
  86. $item['templateid'] = $item['temp_id'];
  87. switch ((int)$item['temp_type']) {
  88. case 1:
  89. $item['type'] = '验证码';
  90. break;
  91. case 2:
  92. $item['type'] = '通知';
  93. break;
  94. case 30:
  95. $item['type'] = '营销短信';
  96. break;
  97. }
  98. }
  99. return $list;
  100. }
  101. /**
  102. * 退出
  103. * @author Qinii
  104. * @day 9/11/21
  105. */
  106. public function logout()
  107. {
  108. Cache::delete('sms_account');
  109. Cache::delete('serve_account');
  110. app()->make(ConfigValueRepository::class)->clearBykey(['serve_account','serve_token'], 0);
  111. }
  112. }