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; $res = Db::name('user_car_remind')->where($remindWhere)->update($data); if (!$res) { throw new Exception('更新保养提醒失败'); } } } else { $data['createtime'] = $time; $res = Db::name('user_car_remind')->insertGetId($data); if (!$res) { throw new Exception('记录保养提醒失败'); } } } } catch (Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 预约通知商家 * @return void */ public function preOrderToShop($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $companyId = isset($params['company_id']) ? $params['company_id'] : 0; $preOrderId = isset($params['id']) ? $params['id'] : 0; $templatePreorder = config('ali_sms_template'); $template = isset($templatePreorder['order_to_c']) ? $templatePreorder['order_to_c'] : ''; if (!empty($template)) { //商家店长 $companyStaffParams = ['type'=>1,'company_id'=>$companyId]; $companyStaff = CompanyStaff::getStaffList($companyStaffParams); $mobile = isset($companyStaff[0]) ? $companyStaff[0]['mobile'] : ''; //预约信息 $preOrderWhere['id'] = $preOrderId; $preOrder = model('PreOrder')->where($preOrderWhere)->find(); $name = isset($preOrder['name']) ? $preOrder['name'] : ''; $orderNo = isset($preOrder['pre_order_no']) ? $preOrder['pre_order_no'] : ''; $preTime = !empty($preOrder['pre_time']) ? date('Y-m-d H:i:s',$preOrder['pre_time']) : ''; $params = [ 'template' => $template,//短息模版 'mobile' => $mobile, //手机号 'data_params' => [ 'name' => $name, //联系人 'order_no' => $orderNo, //单号 'time' => date('Y-m-d H:i:s',$preTime),//预约时间 ],//短信参数 ]; $smsRes = $this->send($params); if (!$smsRes['status']) { Log::error('预约通知商家短信发送失败:params:'.json_encode($params)); } } } catch (Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } /** * 订单通知商家 * @return void */ public function orderToShop($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $companyId = isset($params['company_id']) ? $params['company_id'] : 0; $orderId = isset($params['id']) ? $params['id'] : 0; $templatePreorder = config('ali_sms_template'); $template = isset($templatePreorder['order_to_c']) ? $templatePreorder['order_to_c'] : ''; if (!empty($template)) { //商家店长 $companyStaffParams = ['type'=>1,'company_id'=>$companyId]; $companyStaff = CompanyStaff::getStaffList($companyStaffParams); $mobile = isset($companyStaff[0]) ? $companyStaff[0]['mobile'] : ''; //预约信息 $preOrderWhere['id'] = $orderId; $preOrder = model('Order')->where($preOrderWhere)->find(); $name = isset($preOrder['user_name']) ? $preOrder['user_name'] : ''; $orderNo = isset($preOrder['orderno']) ? $preOrder['orderno'] : ''; $orderTime = !empty($preOrder['createtime']) ? date('Y-m-d H:i:s',$preOrder['createtime']) : ''; $params = [ 'template' => $template,//短息模版 'mobile' => $mobile, //手机号 'data_params' => [ 'name' => $name, //联系人 'order_no' => $orderNo,//单号 'time' => date('Y-m-d H:i:s',$orderTime),//时间 ],//短信参数 ]; $smsRes = $this->send($params); if (!$smsRes['status']) { Log::error('预约通知商家短信发送失败:params:'.json_encode($params)); } } } catch (Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } }