SmsService.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\common\service;
  3. use app\common\library\Alisms;
  4. use think\Db;
  5. use think\Exception;
  6. class SmsService
  7. {
  8. private $model = null;
  9. /**
  10. * 初始化方法
  11. */
  12. public function __construct()
  13. {
  14. $this->model = Db::name('sms');
  15. }
  16. /**
  17. * 发送短息
  18. * @return void
  19. */
  20. public function send($params=[])
  21. {
  22. $result = [
  23. 'status' => 1,
  24. 'msg' => '操作成功',
  25. 'data' => [],
  26. ];
  27. try {
  28. $dataParams = isset($params['data_params']) ? $params['data_params'] : [];
  29. //配置
  30. $config = config('alisms');
  31. if (isset($params['template'])) {
  32. $config['template'] = $params['template'];
  33. }
  34. $alisms = new Alisms();
  35. $result = $alisms->mobile($params['mobile'])
  36. ->template($config['template'])
  37. ->param($dataParams)
  38. ->send();
  39. if (!$result) {
  40. throw new Exception('发送消息失败');
  41. }
  42. } catch (Exception $e) {
  43. $result['status'] = 0;
  44. $result['msg'] = $e->getMessage();
  45. }
  46. return $result;
  47. }
  48. /**
  49. * 保养提醒保存
  50. * @return void
  51. */
  52. public function carRemindSave($params=[])
  53. {
  54. $result = [
  55. 'status' => 1,
  56. 'msg' => '操作成功',
  57. 'data' => [],
  58. ];
  59. try {
  60. $orderId = isset($params['order_id']) ? $params['order_id'] : 0;
  61. $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
  62. $userId = isset($params['user_id']) ? $params['user_id'] : 0;
  63. $carId = isset($params['car_id']) ? $params['car_id'] : 0;
  64. $carNo = isset($params['car_number']) ? $params['car_number'] : '';
  65. $upkeepTime = isset($params['upkeep_time']) ? $params['upkeep_time'] : 0;
  66. $remindTime = !empty($upkeepTime) ? $upkeepTime - 86400 : 0;
  67. $time = time();
  68. if ($remindTime > 0 && $upkeepTime > $time) {
  69. $data = [
  70. 'order_id' => $orderId, //订单ID
  71. 'company_id' => $companyId, //门店ID
  72. 'user_id' => $userId, //用户ID
  73. 'car_id' => $carId, //车辆ID
  74. 'car_number' => $carNo, //车牌号
  75. 'upkeep_time' => $upkeepTime,//保养时间
  76. 'remind_time' => $remindTime,//提醒时间
  77. ];
  78. $remindWhere['user_id'] = $userId;
  79. $remindWhere['company_id'] = $companyId;
  80. $remindWhere['car_id'] = $carId;
  81. $userCarRemind = Db::name('user_car_remind')->where($remindWhere)->find();
  82. if (!empty($userCarRemind)) {
  83. if ($upkeepTime != $userCarRemind['upkeep_time']) {
  84. $data['is_remind'] = 0;
  85. $data['updatetime'] = $time;
  86. $result = Db::name('user_car_remind')->where($remindWhere)->update($data);
  87. if (!$result) {
  88. throw new Exception('更新保养提醒失败');
  89. }
  90. }
  91. } else {
  92. $data['createtime'] = $time;
  93. $result = Db::name('user_car_remind')->insertGetId($data);
  94. if (!$result) {
  95. throw new Exception('记录保养提醒失败');
  96. }
  97. }
  98. }
  99. } catch (Exception $e) {
  100. $result['status'] = 0;
  101. $result['msg'] = $e->getMessage();
  102. }
  103. return $result;
  104. }
  105. }