| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // |
- // +----------------------------------------------------------------------
- // +----------------------------------------------------------------------
- // | Links模型
- // +----------------------------------------------------------------------
- namespace app\admin\model\links;
- use think\facade\Db;
- use think\Model;
- /**
- * 模型
- */
- class Links extends Model
- {
- protected $autoWriteTimestamp = true;
- public function getStatusList()
- {
- return ['未通过', '已通过'];
- }
- public static function onBeforeWrite($row)
- {
- if (isset($row['termsname']) && $row['termsname']) {
- $res = Terms::where(["name" => $row['termsname'], "module" => "links"])->find();
- if ($res > 0) {
- throw new \Exception("该分类已经存在!");
- }
- $term = Terms::create([
- "name" => $row['termsname'],
- "module" => "links",
- ]);
- $row['terms_id'] = $term->id;
- }
- }
- public static function onBeforeDelete($row)
- {
- Db::name('links_data')->where('did', $row->id)->delete();
- }
- }
|