SupplyDemandInfo.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\model\supply_demand\SupplyDemandCate;
  20. use app\common\service\FileService;
  21. use app\common\model\user\User;
  22. use think\model\concern\SoftDelete;
  23. /**
  24. * 服务管理模型
  25. * Class ArticleCate
  26. * @package app\common\model\article;
  27. */
  28. class SupplyDemandInfo extends BaseModel
  29. {
  30. use SoftDelete;
  31. protected $deleteTime = 'delete_time';
  32. /**
  33. * @notes 关联用户
  34. * @return \think\model\relation\HasMany
  35. * @author 段誉
  36. * @date 2022/10/19 16:59
  37. */
  38. public function user()
  39. {
  40. return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar,account');
  41. }
  42. /**
  43. * @notes 关联分类
  44. * @return \think\model\relation\HasMany
  45. * @author 段誉
  46. * @date 2022/10/19 16:59
  47. */
  48. public function cateInfo()
  49. {
  50. return $this->hasOne(SupplyDemandCate::class, 'id', 'cate_id')->field('id,name');
  51. }
  52. public function area(){
  53. return $this->hasOne(AssetArea::class,'id','area_id');
  54. }
  55. /**
  56. * @notes 状态描述
  57. * @param $value
  58. * @param $data 状态 0 新增待发布 1审核中 2 审核成功 3审核失败
  59. * @return string
  60. * @author 段誉
  61. * @date 2022/9/15 11:25
  62. */
  63. public function getStatusDescAttr($value,$data){
  64. $status = $data['status'];
  65. $desc = [
  66. 0 => '新增待提交',
  67. 1 => '审核中',
  68. 2 => '审核成功',
  69. 3 => '审核失败',
  70. ];
  71. return $desc[$status] ?? '';
  72. }
  73. public function getTypeDescAttr($value,$data){
  74. $type = $data['type'];
  75. $desc = [
  76. 1 => '供应',
  77. 2 => '需求',
  78. ];
  79. return $desc[$type] ?? '';
  80. }
  81. /**
  82. * @notes 设置图片域名
  83. * @param $value
  84. * @param $data
  85. * @return array|string|string[]|null
  86. * @author 段誉
  87. * @date 2022/9/28 10:17
  88. */
  89. public function getContentAttr($value, $data)
  90. {
  91. return get_file_domain($value);
  92. }
  93. /**
  94. * @notes 清除图片域名
  95. * @param $value
  96. * @param $data
  97. * @return array|string|string[]
  98. * @author 段誉
  99. * @date 2022/9/28 10:17
  100. */
  101. public function setContentAttr($value, $data)
  102. {
  103. return clear_file_domain($value);
  104. }
  105. /**
  106. * @notes 清除图片域名
  107. * @param $value
  108. * @param $data
  109. * @return array|string|string[]
  110. * @author 段誉
  111. * @date 2022/9/28 10:17
  112. */
  113. public function setImagesAttr($value)
  114. {
  115. if(empty($value)){
  116. return '';
  117. }
  118. $imagesArr = explode(',',$value);
  119. $imagesStr = '';
  120. foreach($imagesArr as $k=>$v){
  121. if($k==0){
  122. $imagesStr = clear_file_domain($v);
  123. }else{
  124. $imagesStr .=','. clear_file_domain($v);
  125. }
  126. }
  127. return $imagesStr;
  128. }
  129. /**
  130. * @notes 加图片域名
  131. * @param $value
  132. * @param $data
  133. * @return array|string|string[]
  134. * @author 段誉
  135. * @date 2022/9/28 10:17
  136. */
  137. public function getImagesAttr($value,$data)
  138. {
  139. if(empty($data['images'])) return '';
  140. $imagesArr = explode(',',$data['images']);
  141. $imagesStr = '';
  142. foreach($imagesArr as $k=>$v){
  143. if($k==0){
  144. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  145. }else{
  146. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  147. }
  148. }
  149. return $imagesStr;
  150. }
  151. }