123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace app\common\service;
- use think\Db;
- use think\Exception;
- use think\Log;
- class PreOrderService
- {
- private $model = null;
- /**
- * 初始化方法
- */
- public function __construct()
- {
- $this->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;
- }
- }
|