PreOrderService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\common\service;
  3. use think\Db;
  4. use think\Exception;
  5. use think\Log;
  6. class PreOrderService
  7. {
  8. private $model = null;
  9. /**
  10. * 初始化方法
  11. */
  12. public function __construct()
  13. {
  14. $this->model = Db::name('pre_order');
  15. }
  16. /**
  17. * 预约发送短息
  18. * @return void
  19. */
  20. public function preOrderToUser($params=[])
  21. {
  22. $result = [
  23. 'status' => 1,
  24. 'msg' => '操作成功',
  25. 'data' => [],
  26. ];
  27. try {
  28. $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
  29. $name = isset($params['name']) ? $params['name'] : '';
  30. $mobile = isset($params['mobile']) ? $params['mobile'] : '';
  31. $preTime = isset($params['pre_time']) ? $params['pre_time'] : 0;
  32. $templatePreorder = config('ali_sms_template');
  33. $template = isset($templatePreorder['pro_order_u']) ? $templatePreorder['pro_order_u'] : '';
  34. if (!empty($template)) {
  35. if (!empty($mobile)) {
  36. //尊敬的${name}先生/女士,您在中蓝养车保养预约成功,预约门店:${mendian},预约时间:${time}
  37. $service = new SmsService();
  38. $where['id'] = $companyId;
  39. $company = model('Company')->where($where)->find();
  40. $companyName = isset($company['name']) ? $company['name'] : '';
  41. $params = [
  42. 'template' => $template,//短息模版
  43. 'mobile' => $mobile, //手机号
  44. 'data_params' => [
  45. 'name' => $name, //联系人
  46. 'mendian' => $companyName,//门店
  47. 'time' => date('Y-m-d H:i:s',$preTime),//预约时间
  48. ],//短信参数
  49. ];
  50. $smsRes = $service->send($params);
  51. if (!$smsRes['status']) {
  52. Log::error('短信发送失败:params:'.json_encode($params));
  53. }
  54. }
  55. }
  56. } catch (Exception $e) {
  57. $result['status'] = 0;
  58. $result['msg'] = $e->getMessage();
  59. }
  60. return $result;
  61. }
  62. /**
  63. * 预约发送短息
  64. * @return void
  65. */
  66. public function preOrderToShop($params=[])
  67. {
  68. $result = [
  69. 'status' => 1,
  70. 'msg' => '操作成功',
  71. 'data' => [],
  72. ];
  73. try {
  74. $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
  75. $name = isset($params['name']) ? $params['name'] : '';
  76. $preTime = isset($params['pre_time']) ? $params['pre_time'] : 0;
  77. $templatePreorder = config('ali_sms_template');
  78. $template = isset($templatePreorder['pro_order_c']) ? $templatePreorder['pro_order_c'] : '';
  79. if (!empty($template)) {
  80. $staffWhere = [
  81. 'status' => 1,
  82. 'type' => 1,//类型:1=商家,2=员工
  83. 'company_id' => $companyId,
  84. ];
  85. $companyStaff = model('CompanyStaff')->with(['company'])->where($staffWhere)->find();
  86. if (!empty($companyStaff)) {
  87. //尊敬的${name}先生/女士,您在中蓝养车保养预约成功,预约门店:${mendian},预约时间:${time}
  88. $service = new SmsService();
  89. $mobile = $companyStaff['mobile']; //商家手机号
  90. $company = isset($companyStaff['company']) ? $companyStaff['company'] : [];
  91. $companyName = isset($company['name']) ? $company['name'] : '';
  92. $params = [
  93. 'template' => $template,//短息模版
  94. 'mobile' => $mobile, //手机号
  95. 'data_params' => [
  96. 'name' => $name, //联系人
  97. 'mendian' => $companyName,//门店
  98. 'time' => $preTime, //预约时间
  99. ],//短信参数
  100. ];
  101. $smsRes = $service->send($params);
  102. if (!$smsRes['status']) {
  103. Log::error('短信发送失败:params:'.json_encode($params));
  104. }
  105. }
  106. }
  107. } catch (Exception $e) {
  108. $result['status'] = 0;
  109. $result['msg'] = $e->getMessage();
  110. }
  111. return $result;
  112. }
  113. }