Links.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | Links模型
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\model\links;
  15. use think\facade\Db;
  16. use think\Model;
  17. /**
  18. * 模型
  19. */
  20. class Links extends Model
  21. {
  22. protected $autoWriteTimestamp = true;
  23. public function getStatusList()
  24. {
  25. return ['未通过', '已通过'];
  26. }
  27. public static function onBeforeWrite($row)
  28. {
  29. if (isset($row['termsname']) && $row['termsname']) {
  30. $res = Terms::where(["name" => $row['termsname'], "module" => "links"])->find();
  31. if ($res > 0) {
  32. throw new \Exception("该分类已经存在!");
  33. }
  34. $term = Terms::create([
  35. "name" => $row['termsname'],
  36. "module" => "links",
  37. ]);
  38. $row['terms_id'] = $term->id;
  39. }
  40. }
  41. public static function onBeforeDelete($row)
  42. {
  43. Db::name('links_data')->where('did', $row->id)->delete();
  44. }
  45. }