SupplyDemandCate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\supply_demand;
  15. use app\common\model\agricultural_machinery\ServiceCategory;
  16. use app\common\model\BaseModel;
  17. use app\common\model\asset\AssetArea;
  18. use app\common\model\recharge\RechargeOrder;
  19. use app\common\service\FileService;
  20. use app\common\model\User\User;
  21. use think\model\concern\SoftDelete;
  22. /**
  23. * 供需分类模型
  24. * Class ArticleCate
  25. * @package app\common\model\article;
  26. */
  27. class SupplyDemandCate extends BaseModel
  28. {
  29. use SoftDelete;
  30. protected $deleteTime = 'delete_time';
  31. /**
  32. * @notes 关联用户
  33. * @return \think\model\relation\HasMany
  34. * @author 段誉
  35. * @date 2022/10/19 16:59
  36. */
  37. public function user()
  38. {
  39. return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar,account');
  40. }
  41. /**
  42. * @notes 状态描述
  43. * @param $value
  44. * @param $data 状态 0 新增待发布 1审核中 2 审核成功 3审核失败
  45. * @return string
  46. * @author 段誉
  47. * @date 2022/9/15 11:25
  48. */
  49. public function getStatusDescAttr($value,$data){
  50. $status = $data['status'];
  51. $desc = [
  52. 0 => '隐藏',
  53. 1 => '显示',
  54. ];
  55. return $desc[$status] ?? '';
  56. }
  57. public function getTypeDescAttr($value,$data){
  58. $type = $data['type'];
  59. $desc = [
  60. 1 => '供应',
  61. 2 => '需求',
  62. ];
  63. return $desc[$type] ?? '';
  64. }
  65. /**
  66. * @notes 设置图片域名
  67. * @param $value
  68. * @param $data
  69. * @return array|string|string[]|null
  70. * @author 段誉
  71. * @date 2022/9/28 10:17
  72. */
  73. public function getContentAttr($value, $data)
  74. {
  75. return get_file_domain($value);
  76. }
  77. /**
  78. * @notes 清除图片域名
  79. * @param $value
  80. * @param $data
  81. * @return array|string|string[]
  82. * @author 段誉
  83. * @date 2022/9/28 10:17
  84. */
  85. public function setContentAttr($value, $data)
  86. {
  87. return clear_file_domain($value);
  88. }
  89. /**
  90. * @notes 清除图片域名
  91. * @param $value
  92. * @param $data
  93. * @return array|string|string[]
  94. * @author 段誉
  95. * @date 2022/9/28 10:17
  96. */
  97. public function setImagesAttr($value)
  98. {
  99. $imagesArr = explode(',',$value);
  100. $imagesStr = '';
  101. foreach($imagesArr as $k=>$v){
  102. if($k==0){
  103. $imagesStr = clear_file_domain($v);
  104. }else{
  105. $imagesStr .=','. clear_file_domain($v);
  106. }
  107. }
  108. return $imagesStr;
  109. }
  110. /**
  111. * @notes 加图片域名
  112. * @param $value
  113. * @param $data
  114. * @return array|string|string[]
  115. * @author 段誉
  116. * @date 2022/9/28 10:17
  117. */
  118. public function getImagesAttr($value,$data)
  119. {
  120. $imagesArr = explode(',',$data['images']);
  121. $imagesStr = '';
  122. foreach($imagesArr as $k=>$v){
  123. if($k==0){
  124. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  125. }else{
  126. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  127. }
  128. }
  129. return $imagesStr;
  130. }
  131. }