CustomMediaPush.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\model;
  3. use think\Log;
  4. use think\Model;
  5. use app\common\constants\OfficialAccount;
  6. use app\common\constants\Message;
  7. use app\common\constants\Common;
  8. use app\common\constants\Custom;
  9. class CustomMediaPush extends Model
  10. {
  11. // 表名
  12. protected $table = 'custom_media_push';
  13. // 自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. // 追加属性
  19. protected $append = [
  20. 'message_type_text',
  21. 'official_account_type_text',
  22. 'sendtime_text',
  23. 'status_text'
  24. ];
  25. public function getMessageTypeList()
  26. {
  27. return ['0' => __('Message_type 0'),'1' => __('Message_type 1')];
  28. }
  29. public function getOfficialAccountTypeList()
  30. {
  31. return ['0' => __('Official_account_type 0'),'1' => __('Official_account_type 1')];
  32. }
  33. public function getStatusList()
  34. {
  35. return ['0' => __('Status 0'),'1' => __('Status 1'),'2' => __('Status 2')];
  36. }
  37. public function getMessageTypeTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : $data['message_type'];
  40. $list = $this->getMessageTypeList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getOfficialAccountTypeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : $data['official_account_type'];
  46. $list = $this->getOfficialAccountTypeList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getSendtimeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : $data['sendtime'];
  52. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  53. }
  54. public function getStatusTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : $data['status'];
  57. $list = $this->getStatusList();
  58. return isset($list[$value]) ? $list[$value] : '';
  59. }
  60. protected function setSendtimeAttr($value)
  61. {
  62. return $value && !is_numeric($value) ? strtotime($value) : $value;
  63. }
  64. /**
  65. * 逻辑删除素材
  66. * @param $mediaId 素材ID
  67. * @return int|bool
  68. */
  69. public function deleteMediaPush($mediaPushId)
  70. {
  71. return $this->save(['status' => Custom::CUSTOM_MEDIA_PUSH_STATUS_DELETE], ['id' => $mediaPushId]);
  72. }
  73. /**
  74. * @param $id custom_media_push 表中的ID
  75. * @return array
  76. * @throws \think\Exception
  77. * @throws \think\exception\DbException
  78. */
  79. public function getCustomInfoById($id)
  80. {
  81. $data = $this->get(['id'=>$id])->toArray();
  82. return $data;
  83. }
  84. }