Comjobs.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class Comjobs extends Model
  6. {
  7. use SoftDelete;
  8. protected $deleteTime = 'deletetime';
  9. protected $defaultSoftDelete = 0;
  10. // 设置字段信息
  11. protected $schema = [
  12. 'id' => 'int',
  13. 'workerid' => 'int',
  14. 'title' => 'string',
  15. 'video' => 'string',
  16. 'cateid' => 'int',
  17. 'province' => 'string',
  18. 'city' => 'string',
  19. 'district' => 'string',
  20. 'agegroup' => 'string',
  21. 'tags' => 'string',
  22. 'enddate' => 'int',
  23. 'requirement' => 'string',
  24. 'comdetails' => 'string',
  25. 'picall' => 'string',
  26. 'companydetails' => 'string',
  27. 'retmoney' => 'int',
  28. 'wtype' => 'tinyint',
  29. 'bwagall' => 'string',
  30. 'zwagall' => 'string',
  31. 'fwagall' => 'string',
  32. 'telephone' => 'string',
  33. 'remark' => 'string',
  34. 'status' => 'tinyint',
  35. 'priority' => 'int',
  36. 'updatetime' => 'int',
  37. 'createtime' => 'int',
  38. 'volume' => 'int',
  39. 'recruitment_cate' => 'int',
  40. 'latitude' => 'float',
  41. 'longitude' => 'float',
  42. 'address' => 'string',
  43. 'community' => 'string',
  44. 'recruit_num' => 'int',
  45. 'is_worry' => 'tinyint',
  46. 'education' => 'string',
  47. 'emp_time' => 'string',
  48. 'company_name' => 'string',
  49. 'contact' => 'string',
  50. 'third_id' => 'int',
  51. 'num' => 'int',
  52. ];
  53. // 设置字段自动转换类型
  54. protected $type = [
  55. 'tags' => 'json',
  56. 'picall' => 'json',
  57. 'emp_time' => 'json',
  58. 'enddate' => 'timestamp:Y-m-d',
  59. 'updatetime' => 'timestamp:Y-m-d H:i:s',
  60. 'createtime' => 'timestamp:Y-m-d H:i:s',
  61. ];
  62. // 设置JSON数据返回数组
  63. protected $jsonAssoc = true;
  64. public function getWtypeTextAttr($value, $data)
  65. {
  66. $wtype = [1 => '按月', 2 => '按时', 3 => '按件', 4 => '按项目', 5 => '其他'];
  67. return $wtype[$data['wtype']];
  68. }
  69. public function getRecruitmentCateTextAttr($value, $data)
  70. {
  71. $recruitment_cate = [1 => '普通招聘', 2 => '悬赏聘'];
  72. return $recruitment_cate[$data['recruitment_cate']];
  73. }
  74. public function getStatusTextAttr($value, $data)
  75. {
  76. $status = [1 => '待修改', 2 => '待审核', 3 => '已上架', 4 => '已停招', 5 => '已下架'];
  77. return $status[$data['status']];
  78. }
  79. // 关联ComjobsCate
  80. public function comjobsCate()
  81. {
  82. return $this->hasOne(ComjobsCate::class, "id", "cateid");
  83. }
  84. // 关联Worker
  85. public function worker()
  86. {
  87. return $this->hasOne(Worker::class, "id", "workerid")->removeOption('soft_delete');
  88. }
  89. // 关联ComjobsLog
  90. public function comjobsLog()
  91. {
  92. return $this->hasMany(ComjobsLog::class, "comjobsid", "id");
  93. }
  94. public function ageCode()
  95. {
  96. return $this->hasOne(RensheCode::class, 'name', 'agegroup');
  97. }
  98. public function educationCode()
  99. {
  100. return $this->hasOne(RensheCode::class, 'name', 'agegroup');
  101. }
  102. public function getEmpCodeAttr($value, $data)
  103. {
  104. $emp_time = json_decode($data['emp_time'], true);
  105. if (empty($emp_time)) {
  106. return '';
  107. }
  108. $emp_code = [];
  109. $emp_list = RensheCode::where('type', 'emp_time')->column('code', 'name');
  110. foreach ($emp_time as $v) {
  111. if (!empty($emp_list[$v])) {
  112. $emp_code[] = $emp_list[$v];
  113. }
  114. }
  115. return implode(',', $emp_code);
  116. }
  117. public function getTagsCodeAttr($value, $data)
  118. {
  119. $tags = json_decode($data['tags'], true);
  120. if (empty($tags)) {
  121. return '';
  122. }
  123. $tags_code = [];
  124. $tags_list = RensheCode::where('type', 'welfare')->column('code', 'name');
  125. foreach ($tags as $v) {
  126. if (!empty($tags_list[$v])) {
  127. $tags_code[] = $tags_list[$v];
  128. }
  129. }
  130. return implode(',', $tags_code);
  131. }
  132. }