Service.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\extra\basic;
  3. use app\model\system\SystemConfig;
  4. use Overtrue\EasySms\Strategies\OrderStrategy;
  5. class Service
  6. {
  7. /**
  8. * @var null
  9. */
  10. protected $mode = null;
  11. /**
  12. * 白名单
  13. * @var array|string[]
  14. */
  15. protected array $mobileWhite = ["18665619195","18665619196","18665619198","18665619199","18665619191","18665619192","18665619193","18665619194"];
  16. /**
  17. * 短信配置
  18. * @param int $type 1 系统配置 2 代理配置
  19. * @return array
  20. */
  21. protected function smsConfig(int $type = 1): array
  22. {
  23. $sms = (new SystemConfig)->where("type","sms")->column("value","name");
  24. return [
  25. "config" => [
  26. 'enable' => true,
  27. 'timeout' => 5.0,
  28. "default" => [
  29. "strategy" => OrderStrategy::class,
  30. "gateways" => [$sms['sms_type']]
  31. ],
  32. "gateways" => [
  33. 'errorlog' => [
  34. 'file' => runtime_path().'/tmp/easy-sms.log',
  35. ],
  36. 'aliyun' => [
  37. 'access_key_id' => $sms['AccessKeyId'],
  38. 'access_key_secret' => $sms['AccessKeySecret'],
  39. 'sign_name' => trim($sms['sign']),
  40. ],
  41. ]
  42. ],
  43. "template" => $sms['login']
  44. ];
  45. }
  46. /**
  47. * 默认排序筛选
  48. * @param array $param
  49. * @param string $prefix
  50. * @param array $filter
  51. * @return string[]
  52. */
  53. public function defaultSort(array $param = [],string $prefix = "",array $filter = []): array
  54. {
  55. if (!empty($prefix)) $prefix = $prefix.".";
  56. if (isset($param['order']) && $param['order'] == 'descending'){
  57. $orderBy = ["{$prefix}{$param['field']}" => "desc"];
  58. } else if (isset($param['order']) && $param['order'] == 'ascending'){
  59. $orderBy = ["{$prefix}{$param['field']}" => "asc"];
  60. } else {
  61. $orderBy = ["{$prefix}create_at" => "desc"];
  62. }
  63. return $orderBy;
  64. }
  65. /**
  66. * @param array $param 参数
  67. * @param array $filter 过滤器
  68. * @param string $prefix 链表前缀
  69. * @param string $join 链表表名
  70. * @param string $field 字段
  71. * @param string $forKey 链表首字母
  72. * @param string $localKey 被链表首字母
  73. */
  74. protected function searchVal(array $param = [],array $filter = [],string $prefix = "",string $join = "",string $field = "",string $forKey = "",string $localKey = "")
  75. {
  76. $orderBy = $this->defaultSort($param,$prefix);
  77. $commonFilter = [];
  78. // 起止时间
  79. if (!empty($param['create'])) {
  80. $times = between_time($param['create']);
  81. $start = date('Y-m-d',$times['start_time']);
  82. $end = date('Y-m-d',($times['end_time'] + 86400));
  83. $commonFilter[] = ['create_at', '>=', $start ];
  84. $commonFilter[] = ['create_at', '<', $end ];
  85. }
  86. $filter = array_merge($filter,$commonFilter);
  87. if (!empty($join)) {
  88. $this->mode = $this->mode->alias('a')->join("{$join} {$prefix}","a.{$forKey} = {$prefix}.{$localKey}")->field($field);
  89. }
  90. return $this->mode->order($orderBy)->where($filter);
  91. }
  92. }