CrmebServeServices.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace ln\services;
  3. use app\common\repositories\system\config\ConfigValueRepository;
  4. use ln\services\express\Express;
  5. use ln\services\product\Product;
  6. use ln\services\serve\Serve;
  7. use ln\services\sms\Sms;
  8. use think\facade\Cache;
  9. /**
  10. * 平台服务入口
  11. * Class ServeServices
  12. * @package ln\services
  13. */
  14. class CrmebServeServices
  15. {
  16. /**
  17. * SmsTemplateApplyServices constructor.
  18. * @param FormBuilder $builder
  19. */
  20. public function __construct()
  21. {
  22. }
  23. /**
  24. * 获取配置
  25. * @return array
  26. */
  27. public function getConfig(array $config = [])
  28. {
  29. return array_merge([
  30. 'account' => systemConfig('serve_account'),
  31. 'secret' => systemConfig('serve_token')
  32. ], $config);
  33. }
  34. /**
  35. * 短信
  36. * @return Sms
  37. */
  38. public function sms(array $config = [])
  39. {
  40. $account = systemConfig('sms_account');
  41. if ($account){
  42. $password = md5($account.systemConfig('sms_token'));
  43. $res = $this->user()->login($account, $password);
  44. if($res){
  45. Cache::set('serve_account', $account);
  46. $arr = [
  47. 'serve_account' => $account,
  48. 'serve_token' => $password,
  49. ];
  50. app()->make(ConfigValueRepository::class)->setFormData($arr, 0);
  51. Cache::delete('sms_account');
  52. request()->clearCache();
  53. }
  54. }
  55. return app()->make(Sms::class, [$this->getConfig($config)]);
  56. }
  57. /**
  58. * 复制商品
  59. * @return Product
  60. */
  61. public function copy(array $config = [])
  62. {
  63. return app()->make(Product::class, [$this->getConfig($config)]);
  64. }
  65. /**
  66. * 电子面单
  67. * @return Express
  68. */
  69. public function express(array $config = [])
  70. {
  71. return app()->make(Express::class, [$this->getConfig($config)]);
  72. }
  73. /**
  74. * 用户
  75. * @return Serve
  76. */
  77. public function user(array $config = [])
  78. {
  79. return app()->make(Serve::class, [$this->getConfig($config)]);
  80. }
  81. /**
  82. * 获取短信模板
  83. * @param int $page
  84. * @param int $limit
  85. * @param int $type
  86. * @return array
  87. */
  88. public function getSmsTempsList(int $page, int $limit, int $type)
  89. {
  90. $list = $this->sms()->temps($page, $limit, $type);
  91. foreach ($list['data'] as &$item) {
  92. $item['templateid'] = $item['temp_id'];
  93. switch ((int)$item['temp_type']) {
  94. case 1:
  95. $item['type'] = '验证码';
  96. break;
  97. case 2:
  98. $item['type'] = '通知';
  99. break;
  100. case 30:
  101. $item['type'] = '营销短信';
  102. break;
  103. }
  104. }
  105. return $list;
  106. }
  107. }