model = Db::name('pre_order'); } /** * 预约发送短息 * @return void */ public function preOrderToUser($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $companyId = isset($params['company_id']) ? $params['company_id'] : 0; $name = isset($params['name']) ? $params['name'] : ''; $mobile = isset($params['mobile']) ? $params['mobile'] : ''; $preTime = isset($params['pre_time']) ? $params['pre_time'] : 0; $templatePreorder = config('ali_sms_template'); $template = isset($templatePreorder['pro_order_u']) ? $templatePreorder['pro_order_u'] : ''; if (!empty($template)) { if (!empty($mobile)) { //尊敬的${name}先生/女士,您在中蓝养车保养预约成功,预约门店:${mendian},预约时间:${time} $service = new SmsService(); $where['id'] = $companyId; $company = model('Company')->where($where)->find(); $companyName = isset($company['name']) ? $company['name'] : ''; $params = [ 'template' => $template,//短息模版 'mobile' => $mobile, //手机号 'data_params' => [ 'name' => $name, //联系人 'mendian' => $companyName,//门店 'time' => date('Y-m-d H:i:s',$preTime),//预约时间 ],//短信参数 ]; $smsRes = $service->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 preOrderToShop($params=[]) { $result = [ 'status' => 1, 'msg' => '操作成功', 'data' => [], ]; try { $companyId = isset($params['company_id']) ? $params['company_id'] : 0; $name = isset($params['name']) ? $params['name'] : ''; $preTime = isset($params['pre_time']) ? $params['pre_time'] : 0; $templatePreorder = config('ali_sms_template'); $template = isset($templatePreorder['pro_order_c']) ? $templatePreorder['pro_order_c'] : ''; if (!empty($template)) { $staffWhere = [ 'status' => 1, 'type' => 1,//类型:1=商家,2=员工 'company_id' => $companyId, ]; $companyStaff = model('CompanyStaff')->with(['company'])->where($staffWhere)->find(); if (!empty($companyStaff)) { //尊敬的${name}先生/女士,您在中蓝养车保养预约成功,预约门店:${mendian},预约时间:${time} $service = new SmsService(); $mobile = $companyStaff['mobile']; //商家手机号 $company = isset($companyStaff['company']) ? $companyStaff['company'] : []; $companyName = isset($company['name']) ? $company['name'] : ''; $params = [ 'template' => $template,//短息模版 'mobile' => $mobile, //手机号 'data_params' => [ 'name' => $name, //联系人 'mendian' => $companyName,//门店 'time' => $preTime, //预约时间 ],//短信参数 ]; $smsRes = $service->send($params); if (!$smsRes['status']) { Log::error('短信发送失败:params:'.json_encode($params)); } } } } catch (Exception $e) { $result['status'] = 0; $result['msg'] = $e->getMessage(); } return $result; } }