DemandReport.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class DemandReport extends Model
  5. {
  6. // 设置字段信息
  7. protected $schema = [
  8. 'id' => 'int',
  9. 'demandid' => 'int',
  10. 'snatchid' => 'int',
  11. 'workerid' => 'int',
  12. 'agentid' => 'int',
  13. 'brokerid' => 'int',
  14. 'realname' => 'string',
  15. 'mobile' => 'string',
  16. 'idcard' => 'string',
  17. 'arrivetime' => 'string',
  18. 'remark' => 'string',
  19. 'createtime' => 'int'
  20. ];
  21. // 设置字段自动转换类型
  22. protected $type = [
  23. 'createtime' => 'timestamp:Y-m-d H:i'
  24. ];
  25. public function getAgeTextAttr($value,$data)
  26. {
  27. $year = substr($data['idcard'], 6, 4);
  28. $monthDay = substr($data['idcard'], 10, 4);
  29. $age = date('Y') - $year;
  30. if ($monthDay > date('md')) {
  31. $age--;
  32. }
  33. return $age;
  34. }
  35. public function demand()
  36. {
  37. return $this->hasOne(Demand::class, "id", "demandid");
  38. }
  39. public function snatch()
  40. {
  41. return $this->hasOne(DemandSnatch::class, "id", "snatchid");
  42. }
  43. public function worker()
  44. {
  45. return $this->hasOne(Worker::class, "id", "workerid");
  46. }
  47. public function agent()
  48. {
  49. return $this->hasOne(Agent::class, "id", "agentid");
  50. }
  51. public function broker()
  52. {
  53. return $this->hasOne(Broker::class, "id", "brokerid");
  54. }
  55. }