Demand.php 2.9 KB

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