123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace app\common\service;
- use app\common\library\Alisms;
- use think\Db;
- use think\Exception;
- class SmsService
- {
- private $model = null;
- /**
- * 初始化方法
- */
- public function __construct()
- {
- $this->model = Db::name('sms');
- }
- /**
- * 发送短息
- * @return void
- */
- public function send($params=[])
- {
- $result = [
- 'status' => 1,
- 'msg' => '操作成功',
- 'data' => [],
- ];
- try {
- $dataParams = isset($params['data_params']) ? $params['data_params'] : [];
- //配置
- $config = config('alisms');
- if (isset($params['template'])) {
- $config['template'] = $params['template'];
- }
- $alisms = new Alisms();
- $result = $alisms->mobile($params['mobile'])
- ->template($config['template'])
- ->param($dataParams)
- ->send();
- if (!$result) {
- throw new Exception('发送消息失败');
- }
- } catch (Exception $e) {
- $result['status'] = 0;
- $result['msg'] = $e->getMessage();
- }
- return $result;
- }
- /**
- * 保养提醒保存
- * @return void
- */
- public function carRemindSave($params=[])
- {
- $result = [
- 'status' => 1,
- 'msg' => '操作成功',
- 'data' => [],
- ];
- try {
- $orderId = isset($params['order_id']) ? $params['order_id'] : 0;
- $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- $carId = isset($params['car_id']) ? $params['car_id'] : 0;
- $carNo = isset($params['car_number']) ? $params['car_number'] : '';
- $upkeepTime = isset($params['upkeep_time']) ? $params['upkeep_time'] : 0;
- $remindTime = !empty($upkeepTime) ? $upkeepTime - 86400 : 0;
- $time = time();
- if ($remindTime > 0 && $upkeepTime > $time) {
- $data = [
- 'order_id' => $orderId, //订单ID
- 'company_id' => $companyId, //门店ID
- 'user_id' => $userId, //用户ID
- 'car_id' => $carId, //车辆ID
- 'car_number' => $carNo, //车牌号
- 'upkeep_time' => $upkeepTime,//保养时间
- 'remind_time' => $remindTime,//提醒时间
- ];
- $remindWhere['user_id'] = $userId;
- $remindWhere['company_id'] = $companyId;
- $remindWhere['car_id'] = $carId;
- $userCarRemind = Db::name('user_car_remind')->where($remindWhere)->find();
- if (!empty($userCarRemind)) {
- if ($upkeepTime != $userCarRemind['upkeep_time']) {
- $data['is_remind'] = 0;
- $data['updatetime'] = $time;
- $result = Db::name('user_car_remind')->where($remindWhere)->update($data);
- if (!$result) {
- throw new Exception('更新保养提醒失败');
- }
- }
- } else {
- $data['createtime'] = $time;
- $result = Db::name('user_car_remind')->insertGetId($data);
- if (!$result) {
- throw new Exception('记录保养提醒失败');
- }
- }
- }
- } catch (Exception $e) {
- $result['status'] = 0;
- $result['msg'] = $e->getMessage();
- }
- return $result;
- }
- }
|