Blame view

addons/antis/model/SendTemplater.php 3.25 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  <?php

  

  namespace addons\antis\model;

  

  use think\Model;

  

  /**

   *发送通知模板

   */

  class SendTemplater extends Model

  {

  

      // 表名,不含前缀

      protected $name = 'qingdong_send_template';

      // 开启自动写入时间戳字段

      protected $autoWriteTimestamp = 'int';

      // 定义时间戳字段名

      protected $createTime = 'createtime';

      protected $updateTime = 'updatetime';

  

  

      public static function sendEmail($id,$title,$content,$types)

      {

          if($types == 'customer'){

              $customer = Customer::where(['id' => $id])->with(['contacts', 'ownerStaff'])->find();

              if (empty($customer['contacts']['mobile'])) {

                  return false;

              }

              $email=$customer['contacts']['email'];

              $replace = [$customer['name'], $customer['contacts']['name'], $customer['contacts']['email'], $customer['contacts']['mobile'], $customer['create_staff']['name']];

          }elseif($types == 'contacts'){

              $contacts = Contacts::where(['id' => $id])->with(['customer', 'ownerStaff'])->find();

              if (empty($contacts['mobile'])) {

                  return false;

              }

              $email=$contacts['email'];

              $replace = [$contacts['customer']['name'], $contacts['name'], $contacts['email'], $contacts['mobile'], $contacts['owner_staff']['name']];

          }

          $search = ['{{name}}','{{contacts_name}}','{{email}}','{{mobile}}','{{create_staff}}'];

          $content = str_replace($search, $replace, $content);

  

          $model = new \app\common\library\Email();

          $result = $model->to($email)

              ->subject($title)

              ->message($content)

              ->send();

          return $result;

      }

  

      public static function sendSms($id, $template, $params,$types)

      {

          if($types == 'customer'){

              $customer = Customer::where(['id' => $id])->with(['contacts', 'ownerStaff'])->find();

              if (empty($customer['contacts']['mobile'])) {

                  return false;

              }

              $mobile=$customer['contacts']['mobile'];

              $replace = [$customer['name'], $customer['contacts']['name'], $customer['contacts']['email'], $customer['contacts']['mobile'], $customer['create_staff']['name']];

          }elseif($types == 'contacts'){

              $contacts = Contacts::where(['id' => $id])->with(['customer', 'ownerStaff'])->find();

              if (empty($contacts['mobile'])) {

                  return false;

              }

              $mobile=$contacts['mobile'];

              $replace = [$contacts['customer']['name'], $contacts['name'], $contacts['email'], $contacts['mobile'], $contacts['owner_staff']['name']];

          }

          $search = ['{{name}}', '{{contacts_name}}', '{{email}}', '{{mobile}}', '{{create_staff}}'];

          $data=[];

          foreach ($params as $v) {

              $namesinfo = '';

              if($v['content']){

                  $names = explode('{{',$v['content']);

                  if($names[1]){

                      $namesinfo = explode('}}',$names[1])[0];

                  }

              }

              $data[$namesinfo] = str_replace($search, $replace, $v['content']);

          }

  

          return  \app\common\library\Sms::notice($mobile,$data,$template);

      }

  }