SendMessage.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class SendMessage extends Model
  5. {
  6. // 表名
  7. protected $table = 'send_message';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. // 追加属性
  14. protected $append = [
  15. 'message_type_text',
  16. 'subscription_type_text',
  17. 'send_status_text',
  18. 'message_status_text',
  19. 'current_month_count_text',
  20. 'send_time_text',
  21. 'create_time_text',
  22. 'update_time_text',
  23. 'is_save_to_library_text'
  24. ];
  25. public function getMessageTypeList()
  26. {
  27. return ['1' => __('文本类型'),'2' => __('图文类型'),'3' => __('图片消息')];
  28. }
  29. public function getSubscriptionTypeList()
  30. {
  31. return ['1' => __('全部公众号'),'2' => __('指定公众号')];
  32. }
  33. public function getSendStatusList()
  34. {
  35. return [
  36. '1' => __('等待素材处理'),
  37. '2' => __('素材处理中'),
  38. '3' => __('素材处理完成待发送'),
  39. '4' => __('发送中'),
  40. '5' => __('发送完成'),
  41. '6' => __('发送失败(消息内容过期)'),
  42. '7' => __('已删除微信历史消息'),
  43. '8' => __('发送失败(接收人数小于2)')
  44. ];
  45. }
  46. public function getMessageStatusList()
  47. {
  48. return ['1' => __('有效'),'2' => __('失效'),'3' => __('已删除')];
  49. }
  50. public function getCurrentMonthCountList()
  51. {
  52. return ['1' => __('0次'),'2' => __('1次'),'3' => __('2次'),'4' => __('3次')];
  53. }
  54. public function getIsSaveToLibraryList()
  55. {
  56. return ['1' => __('是'),'2' => __('否')];
  57. }
  58. public function getMessageTypeTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : $data['message_type'];
  61. $list = $this->getMessageTypeList();
  62. return isset($list[$value]) ? $list[$value] : '';
  63. }
  64. public function getSubscriptionTypeTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : $data['subscription_type'];
  67. $list = $this->getSubscriptionTypeList();
  68. return isset($list[$value]) ? $list[$value] : '';
  69. }
  70. public function getSendStatusTextAttr($value, $data)
  71. {
  72. $value = $value ? $value : $data['send_status'];
  73. $list = $this->getSendStatusList();
  74. return isset($list[$value]) ? $list[$value] : '';
  75. }
  76. public function getMessageStatusTextAttr($value, $data)
  77. {
  78. $value = $value ? $value : $data['message_status'];
  79. $list = $this->getMessageStatusList();
  80. return isset($list[$value]) ? $list[$value] : '';
  81. }
  82. public function getCurrentMonthCountTextAttr($value, $data)
  83. {
  84. $value = $value ? $value : $data['current_month_count'];
  85. $list = $this->getCurrentMonthCountList();
  86. return isset($list[$value]) ? $list[$value] : '';
  87. }
  88. public function getSendTimeTextAttr($value, $data)
  89. {
  90. $value = $value ? $value : $data['send_time'];
  91. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  92. }
  93. public function getCreateTimeTextAttr($value, $data)
  94. {
  95. $value = $value ? $value : $data['create_time'];
  96. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  97. }
  98. public function getUpdateTimeTextAttr($value, $data)
  99. {
  100. $value = $value ? $value : $data['update_time'];
  101. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  102. }
  103. public function getIsSaveToLibraryTextAttr($value, $data)
  104. {
  105. $value = $value ? $value : $data['is_save_to_library'];
  106. $list = $this->getIsSaveToLibraryList();
  107. return isset($list[$value]) ? $list[$value] : '';
  108. }
  109. protected function setSendTimeAttr($value)
  110. {
  111. return $value && !is_numeric($value) ? strtotime($value) : $value;
  112. }
  113. protected function setCreateTimeAttr($value)
  114. {
  115. return $value && !is_numeric($value) ? strtotime($value) : $value;
  116. }
  117. protected function setUpdateTimeAttr($value)
  118. {
  119. return $value && !is_numeric($value) ? strtotime($value) : $value;
  120. }
  121. }