1
0

Building.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Building extends Model
  5. {
  6. public function getCoverAttr($value){
  7. if(empty($value)) return $value;
  8. $arr = explode(',', $value);
  9. $domain = config('app.ali_oss_bindurl');
  10. foreach($arr as &$item){
  11. $item = 'https://'.$domain.'/'.$item;
  12. }
  13. return $arr;
  14. }
  15. public function setCoverAttr($value){
  16. $domain = config('app.ali_oss_bindurl');
  17. $search = 'https://'.$domain.'/';
  18. return str_replace($search, '', $value);
  19. }
  20. public function getCoverShareImgAttr($value){
  21. if(empty($value)) return $value;
  22. $domain = config('app.ali_oss_bindurl');
  23. return 'https://'.$domain.'/'.$value;
  24. }
  25. public function setCoverShareImgAttr($value){
  26. $domain = config('app.ali_oss_bindurl');
  27. $search = 'https://'.$domain.'/';
  28. return str_replace($search, '', $value);
  29. }
  30. public function getNameAttr($value, $item){
  31. if ($item['community_id']) {
  32. $name = Community::where('id', $item['community_id'])->value('name');
  33. } else {
  34. $name = $value;
  35. }
  36. return $name;
  37. }
  38. public function getPinyinAttr($value, $item){
  39. if ($item['community_id']) {
  40. $name = Community::where('id', $item['community_id'])->field('name,initials')->find();
  41. if($name == null) return '';
  42. if ($name->initials) {
  43. $pinyin = $name->initials;
  44. }else{
  45. $name = $name->name;
  46. if (hanziInitials($name)) {
  47. $pinyin = strtoupper(hanziInitials($name));
  48. } else {
  49. $pinyin = strtoupper(mb_substr($name,0,1));
  50. }
  51. }
  52. } else {
  53. $pinyin = $value;
  54. }
  55. return $pinyin;
  56. }
  57. public function progress(){
  58. return $this->hasMany(BuildingProgress::class, 'building_id', 'id');
  59. }
  60. public function housetype(){
  61. return $this->hasMany(BuildingHousetype::class, 'building_id', 'id');
  62. }
  63. public function materialCase(){
  64. return $this->hasMany(BuildingMaterialCase::class, 'building_id', 'id');
  65. }
  66. public function shareLog(){
  67. return $this->hasMany(ShareLog::class, 'data_id','id');
  68. }
  69. public function employee(){
  70. return $this->hasOne(Employee::class, 'id','employee_id');//->bind(['employee_name'=> 'opt_name']);
  71. }
  72. public function devcase(){
  73. return $this->hasMany(BuildingDevelopCase::class, 'building_id','id');
  74. }
  75. public function construction(){
  76. return $this->hasMany(BuildingConstruction::class, 'building_id','id');
  77. }
  78. }