CustomMedia.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use app\common\constants\Common;
  5. class CustomMedia extends Model
  6. {
  7. // 表名
  8. protected $table = 'custom_media';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. 'is_share_vip_manager_text',
  17. 'is_share_vip_operator_text',
  18. 'message_type_text',
  19. 'status_text'
  20. ];
  21. public function getIsShareVipManagerList()
  22. {
  23. return ['0' => __('Is_share_vip_manager 0'), '1' => __('Is_share_vip_manager 1')];
  24. }
  25. public function getIsShareVipOperatorList()
  26. {
  27. return ['0' => __('Is_share_vip_operator 0'), '1' => __('Is_share_vip_operator 1')];
  28. }
  29. public function getMessageTypeList()
  30. {
  31. return ['0' => __('Message_type 0'), '1' => __('Message_type 1')];
  32. }
  33. public function getStatusList()
  34. {
  35. return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')];
  36. }
  37. public function getIsShareVipManagerTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : $data['is_share_vip_manager'];
  40. $list = $this->getIsShareVipManagerList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getIsShareVipOperatorTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : $data['is_share_vip_operator'];
  46. $list = $this->getIsShareVipOperatorList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getMessageTypeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : $data['message_type'];
  52. $list = $this->getMessageTypeList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : $data['status'];
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. /**
  62. * 逻辑删除素材
  63. * @param $mediaId 素材ID
  64. * @return int|bool
  65. */
  66. public function deleteMedia($mediaId)
  67. {
  68. return $this->save(['status' => Common::STATUS_HIDDEN], ['id' => $mediaId]);
  69. }
  70. }