PlanArchive.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\admin\model\equipment;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class PlanArchive extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'equipment_plan_archive';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = false;
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. ];
  19. public function archive()
  20. {
  21. return $this->belongsTo(Archive::class, 'archive_id')->field('id, model, name');
  22. }
  23. public function addArchives($planId, $archives)
  24. {
  25. $list = [];
  26. $archives = explode(',', $archives);
  27. foreach ($archives as $archiveId) {
  28. $list[] = [
  29. 'plan_id' => $planId,
  30. 'archive_id' => $archiveId
  31. ];
  32. }
  33. $result = $this->saveAll($list);
  34. if (!$result) {
  35. return $this->getError();
  36. }
  37. return true;
  38. }
  39. }