*/ trait DataDelete { /** * 数据删除 * @param array $id * @return \think\response\Json * @throws \Throwable */ public function del($id = []) { Db::startTrans(); try { $this->beforeDelete($id); if (method_exists(static::class, 'delete')) { $this->delete($id); } else { if (!is_array($id)) $id = [$id]; $this->getModel()::softDelete([$this->primary => $id]); } $this->afterDelete($id); Db::commit(); } catch (\Throwable $exception) { Db::rollback(); throw $exception; } return ResponseJson::mixin(true); } /** * 删除之前的数据处理 * @param $id */ public function beforeDelete(&$id){} /** * 删除后的代码执行 * @param $id */ public function afterDelete($id){} }