Demand.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class Demand 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. 'type' => 'int',
  15. 'title' => 'string',
  16. 'video' => 'string',
  17. 'cateid' => 'int',
  18. 'province' => 'string',
  19. 'city' => 'string',
  20. 'district' => 'string',
  21. 'agegroup' => 'string',
  22. 'tags' => 'string',
  23. 'enddate' => 'int',
  24. 'requirement' => 'string',
  25. 'comdetails' => 'string',
  26. 'picall' => 'string',
  27. 'wtype' => 'tinyint',
  28. 'bwagall' => 'string',
  29. 'zwagall' => 'string',
  30. 'ftype' => 'tinyint',
  31. 'fwagall' => 'string',
  32. 'telephone' => 'string',
  33. 'remark' => 'string',
  34. 'status' => 'tinyint',
  35. 'isfree' => 'tinyint',
  36. 'priority' => 'int',
  37. 'updatetime' => 'int',
  38. 'createtime' => 'int',
  39. 'volume' => 'int',
  40. 'telearr' => 'string',
  41. ];
  42. // 设置字段自动转换类型
  43. protected $type = [
  44. 'tags' => 'json',
  45. 'telearr' => 'json',
  46. 'picall' => 'json',
  47. 'enddate' => 'timestamp:Y-m-d',
  48. 'updatetime' => 'timestamp:Y-m-d H:i:s',
  49. 'createtime' => 'timestamp:Y-m-d H:i:s',
  50. ];
  51. // 设置JSON数据返回数组
  52. protected $jsonAssoc = true;
  53. public function gettypeTextAttr($value, $data)
  54. {
  55. $wtype = [1 => '代招', 2 => '劳务派遣'];
  56. return $wtype[$data['wtype']];
  57. }
  58. public function getWtypeTextAttr($value, $data)
  59. {
  60. $wtype = [1 => '按月', 2 => '按时', 3 => '按件', 4 => '按项目', 5 => '其他'];
  61. return $wtype[$data['wtype']];
  62. }
  63. public function getFtypeTextAttr($value, $data)
  64. {
  65. $ftype = [1 => '一次性', 2 => '小时工', 3 => '管理费', 4 => '其他'];
  66. return $ftype[$data['ftype']];
  67. }
  68. public function getStatusTextAttr($value, $data)
  69. {
  70. $status = [1 => '待修改', 2 => '待审核', 3 => '已上架', 4 => '已停招', 5 => '已下架'];
  71. return $status[$data['status']];
  72. }
  73. public function getIsfreeTextAttr($value, $data)
  74. {
  75. $isfree = [1 => '否', 2 => '是'];
  76. return $isfree[$data['isfree']];
  77. }
  78. // 关联DemandCate
  79. public function demandCate()
  80. {
  81. return $this->hasOne(DemandCate::class, "id", "cateid");
  82. }
  83. // 关联Worker
  84. public function worker()
  85. {
  86. return $this->hasOne(Worker::class, "id", "workerid");
  87. }
  88. // 关联DemandLog
  89. public function demandLog()
  90. {
  91. return $this->hasMany(DemandLog::class, "demandid", "id");
  92. }
  93. }