Blame view

addons/qingdong/model/Message2.php 3.7 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  <?php

  

  namespace addons\qingdong\model;

  

  use addons\qingdong\library\Wechat;

  use addons\qingdong\library\WechatEnterprise;

  use fast\Http;

  use think\Exception;

  use think\Model;

  use traits\model\SoftDelete;

  

  /**

   *新提醒消息

   */

  class Message2 extends Model

  {

      use SoftDelete;

  

      // 表名,不含前缀

  

      const   CUSTOMER_TYPE = 'customer';//客户

      const   BUSINESS_TYPE = 'business';//项目

      const   CUSTOMER_RECORD = 'customer_record';//客户跟进

      const   BUSINESS_RECORD= 'business_record';//项目跟进

  

      protected $name = 'qingdong_message_copy';//

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

      protected $autoWriteTimestamp = 'int';

      // 定义时间戳字段名

      protected $createTime = 'createtime';

      protected $updateTime = 'updatetime';

      protected $deleteTime = 'deletetime';

  

  

  

      public static function setRead($id)

      {

          $where = [

              'id' => $id,

              'status' => 0

          ];

          //halt(Message::where($where)->find());

          return Message2::where($where)->update(['read_time' => time(), 'status' => 1]);

      }

  

      /**

       * 添加通知消息

       * @param $relation_type string 类型

       * @param $relation_id int 类型id

       * @param $to_staff_id int 接收人

       * @param $from_staff_id int 发送人

       * @return bool

       * @throws Exception

       */

      public static function addMessage2($relation_type, $relation_id, $to_staff_id, $from_staff_id)

      {

  

          $addMessage = [

              'to_staff_id' => $to_staff_id,

              'from_staff_id' => $from_staff_id,

              'send_time' => time(),

              'createtime'=>time(),

              'updatetime'=>time(),

              'status' => 0,

          ];

          $staff_name = Staff::where('id',$from_staff_id)->value('name');

          switch ($relation_type) {

              case self::CUSTOMER_TYPE:

                  $addMessage['relation_type'] = Message2::CUSTOMER_TYPE;

                  $addMessage['relation_id'] = $relation_id;

                  $content =Customer::where(array('id'=>$relation_id))->value('name');

                  $addMessage['content'] = $staff_name.'新建了'.$content.'客户';

                  break;

              case self::BUSINESS_TYPE:

                  $addMessage['relation_type'] = Message2::BUSINESS_TYPE;

                  $addMessage['relation_id'] = $relation_id;

                  $content =Business::where(array('id'=>$relation_id))->value('name');

                  $addMessage['content'] = $staff_name.'新建了'.$content.'项目';

                  break;

  

              case self::CUSTOMER_RECORD:

                  $addMessage['relation_type'] = Message2::CUSTOMER_RECORD;

                  $addMessage['relation_id'] = $relation_id;

                  $content = Record::where(array('id'=>$relation_id))->value('content');

                  $addMessage['content'] = $content;

                  break;

              case self::BUSINESS_RECORD:

                  $addMessage['relation_type'] = Message2::BUSINESS_RECORD;

                  $addMessage['relation_id'] = $relation_id;

                  $content = Record::where(array('id'=>$relation_id))->value('content');

                  $addMessage['content'] =$content;

                  break;

          }

  

          self::insert($addMessage);

  

          return true;

      }

  

  

  

  

      public function getSendTimeAttr($value)

      {

          return date('Y-m-d H:i:s', $value);

      }

  

      public function fromStaff()

      {

          return $this->hasOne(Staff::class, 'id', 'from_staff_id')->field('id,name');

      }

  

      public function examine()

      {

          return $this->hasOne(ExamineRecord::class, 'id', 'relation_id')->field('id,relation_type,relation_id');

      }

  }